-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.c
73 lines (66 loc) · 1.87 KB
/
draw.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
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akinzeli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 15:44:21 by akinzeli #+# #+# */
/* Updated: 2024/03/19 16:25:20 by akinzeli ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void draw_line(t_env *env, t_final point1, t_final point2)
{
float step;
float x;
float y;
int i;
t_pixcor delta;
i = 0;
delta.dx = point2.x - point1.x;
delta.dy = point2.y - point1.y;
if (fabsf(delta.dx) >= fabsf(delta.dy))
step = fabsf(delta.dx);
else
step = fabsf(delta.dy);
delta.dx = delta.dx / step;
delta.dy = delta.dy / step;
x = point1.x;
y = point1.y;
while (i < step)
{
put_line(env, -x + 1920 / 2 + env->translation + env->mousex, -y + 1080
/ 2 + env->translation - env->mousey, 0xFFFFFF);
x = x + delta.dx;
y = y + delta.dy;
i++;
}
}
void put_line(t_env *env, int x, int y, int color)
{
char *pxl;
if (x >= 0 && x < 1920 && y >= 0 && y < 1080)
{
pxl = env->address + (y * env->line_length + x * (env->bits_by_pixel
/ 8));
*(unsigned int *)pxl = color;
}
}
void draw_background(t_env *env)
{
int h;
int l;
h = 0;
l = 0;
while (h <= 1080)
{
l = 0;
while (l <= 1920)
{
put_line(env, l, h, 0x000000);
l++;
}
h++;
}
}