-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_line.c
executable file
·71 lines (66 loc) · 1.96 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gsferopo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/30 08:53:44 by gsferopo #+# #+# */
/* Updated: 2017/08/28 10:44:32 by gsferopo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int draw_line(t_proc *a, t_draw *d)
{
d->dx = d->x2 - d->x1;
d->dy = d->y2 - d->y1;
d->steps = abs(d->dx) > abs(d->dy) ? abs(d->dx) : abs(d->dy);
d->xinc = d->dx / (float)d->steps;
d->yinc = d->dy / (float)d->steps;
d->x = d->x1;
d->y = d->y1;
d->i = -1;
while (++d->i <= d->steps)
{
a->i = sqrt(pow(d->x2 - d->x1, 2) + pow(d->y2 - d->y1, 2));
if (!(a->i > (a->zoom) * 5))
{
put_pixel(a, d->x, d->y);
d->x += d->xinc;
d->y += d->yinc;
}
}
return (1);
}
int printchar_p2(t_proc *a)
{
t_draw d;
AY = 0;
AX = 0;
while (AY < a->size_y)
{
while (AX < a->size_x)
{
d.x1 = round(ASX / 1000);
d.y1 = round(ASX % 1000);
d.x2 = round(AS[AY + 1][AX] / 1000);
d.y2 = round(AS[AY + 1][AX] % 1000);
draw_line(a, &d);
d.x2 = round(AS[AY][AX + 1] / 1000);
d.y2 = round(AS[AY][AX + 1] % 1000);
draw_line(a, &d);
AX++;
}
AX = 0;
AY++;
}
return (1);
}
int put_pixel(t_proc *a, int x, int y)
{
if (AMX < 6)
mlx_pixel_put(a->mlx, a->win, x, y, BLUE);
else if (AMX > 5)
mlx_pixel_put(a->mlx, a->win, x, y, RED);
return (1);
}