-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment_bis.c
63 lines (58 loc) · 1.8 KB
/
segment_bis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* segment_bis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rrollin <rrollin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/16 16:25:37 by rrollin #+# #+# */
/* Updated: 2022/05/16 16:27:55 by rrollin ### ########.fr */
/* */
/* ************************************************************************** */
#include"fdf.h"
void ft_segment_dx(t_vars *vars, t_point point1, t_point point2)
{
int dx;
int dy;
float e;
int color;
dx = point2.x - point1.x;
dy = point2.y - point1.y;
if (dx < 0)
{
ft_swap_point(&point1, &point2);
dx *= -1;
dy *= -1;
}
e = (float) dy / (float) dx;
while (point1.x <= point2.x)
{
color = ft_get_color(&point1, &point2, point1.x - point2.x + dx, dx);
ft_pixel_put(vars, point1.x, (int) point1.y, color);
point1.x++;
point1.y += e;
}
}
void ft_segment_dy(t_vars *vars, t_point point1, t_point point2)
{
int dx;
int dy;
float e;
int color;
dx = point2.x - point1.x;
dy = point2.y - point1.y;
if (dy < 0)
{
ft_swap_point(&point1, &point2);
dx *= -1;
dy *= -1;
}
e = (float) dx / (float) dy;
while (point1.y <= point2.y)
{
color = ft_get_color(&point1, &point2, point1.y - point2.y + dy, dy);
ft_pixel_put(vars, (int) point1.x, point1.y, color);
point1.y++;
point1.x += e;
}
}