-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_line.c
55 lines (49 loc) · 1.23 KB
/
draw_line.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
/*
** draw_line.c for fdf in /home/coutar_a/Documents/I_graph/tp_04/draw_line
**
** Made by coutar_a
** Login <coutar_a@epitech.net>
**
** Started on Mon Dec 2 17:31:27 2013 coutar_a
** Last update Fri Dec 6 16:05:48 2013 coutar_a
*/
#include "fdf.h"
int draw_line_horizontal(int x1, int y1, int x2, int y2, t_ptr *ptr)
{
int x;
if (x2 < x1)
{
x = x2;
while (x++ <= x1)
mlx_pixel_put(ptr->mlx_ptr, ptr->win_ptr, x, Y_PLOT(x2, y2, x1, y1, x), 0xFFFFFF);
}
if (x2 > x1)
{
x = x1;
while (x++ <= x2)
mlx_pixel_put(ptr->mlx_ptr, ptr->win_ptr, x, Y_PLOT(x1, y1, x2, y2, x), 0xFFFFFF);
}
}
int draw_line_vertical(int x1, int y1, int x2, int y2, t_ptr *ptr)
{
int y;
if (y2 > y1)
{
y = y2;
while (y-- >= y1)
mlx_pixel_put(ptr->mlx_ptr, ptr->win_ptr, X_PLOT(x2, y2, x1, y1, y), y, 0xFFFFFF);
}
if (y1 > y2)
{
y = y1;
while (y-- >= y2)
mlx_pixel_put(ptr->mlx_ptr, ptr->win_ptr, X_PLOT(x1, y1, x2, y2, y), y, 0xFFFFFF);
}
}
int draw_line(int x1, int y1, int x2, int y2, t_ptr *ptr)
{
if (ABS((x2 - x1)) > ABS((y2 - y1)))
draw_line_horizontal(x1, y1, x2, y2, ptr);
if (ABS((x2 - x1)) <= ABS((y2 - y1)))
draw_line_vertical(x1, y1, x2, y2, ptr);
}