-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_image.c
102 lines (95 loc) · 3.32 KB
/
draw_image.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: conguyen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:37:44 by conguyen #+# #+# */
/* Updated: 2022/06/24 19:07:11 by conguyen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static void calc_delta(t_fdf *fdf)
{
fdf->px.dx = abs((int)fdf->px.x1 - (int)fdf->px.x2);
fdf->px.dy = abs((int)fdf->px.y1 - (int)fdf->px.y2);
}
static void get_max_min(t_fdf *fdf, int y, int x)
{
if (fdf->map.max < fdf->map.map[y][x])
fdf->map.max = fdf->map.map[y][x];
if (fdf->map.min > fdf->map.map[y][x])
fdf->map.min = fdf->map.map[y][x];
fdf->map.curr_h = fdf->map.map[y][x];
fdf->map.next_h = fdf->map.map[y][x + 1];
}
static void calc_line_horizontal(t_fdf *fdf, int y, int x)
{
if (x == 0)
{
fdf->px.x1 = 400 - fdf->px.pad_w
- (fdf->flag.proj_x * y) * fdf->flag.zoom;
fdf->px.y1 = ((fdf->flag.proj_y * y) * fdf->flag.zoom + fdf->px.pad_h
- fdf->flag.zoom * 20) - fdf->map.map[y][x] * fdf->flag.h / 10;
}
fdf->px.z = (fdf->map.map[y][x] - fdf->map.map[y][x + 1])
* fdf->flag.h / 10;
fdf->px.x2 = fdf->px.x1 + (fdf->flag.isom_x * fdf->flag.zoom);
fdf->px.y2 = fdf->px.z + fdf->px.y1 + (fdf->flag.para_y * fdf->flag.zoom);
if (y == 0 && x == fdf->map.width - 2)
fdf->flag.pad_modifier = (fdf->px.x2 - 400) / 2;
fdf->px.dx = fdf->px.x1 - fdf->px.x2;
fdf->px.curr_color = fdf->map.color[y][x];
fdf->px.next_color = fdf->map.color[y][x + 1];
calc_delta(fdf);
get_max_min(fdf, y, x);
if (fdf->px.dx > fdf->px.dy)
draw_line_dx(fdf, fdf->px, 0);
else
draw_line_dy(fdf, fdf->px, 1);
fdf->px.y1 = fdf->px.y2;
fdf->px.x1 = fdf->px.x2;
}
static void calc_line_vertical(t_fdf *fdf, int y, int x)
{
if (x == 0)
{
fdf->px.x1 = 401 - fdf->px.pad_w
- (fdf->flag.proj_x * y) * fdf->flag.zoom;
fdf->px.y1 = ((fdf->flag.proj_y * y) * fdf->flag.zoom + fdf->px.pad_h
- fdf->flag.zoom * 20) - fdf->map.map[y][x] * fdf->flag.h / 10;
}
fdf->px.z = (fdf->map.map[y][x] - fdf->map.map[y + 1][x])
* fdf->flag.h / 10;
fdf->px.x2 = fdf->px.x1 - (fdf->flag.proj_x * fdf->flag.zoom);
fdf->px.y2 = fdf->px.z + fdf->px.y1 + (fdf->flag.proj_y * fdf->flag.zoom);
fdf->px.curr_color = fdf->map.color[y][x];
fdf->px.next_color = fdf->map.color[y + 1][x];
fdf->map.curr_h = fdf->map.map[y][x];
fdf->map.next_h = fdf->map.map[y + 1][x];
calc_delta(fdf);
if (fdf->px.dx > fdf->px.dy)
draw_line_dx(fdf, fdf->px, 0);
else
draw_line_dy(fdf, fdf->px, 1);
}
void draw_image(t_fdf *fdf)
{
int x;
int y;
y = 0;
while (y < fdf->map.height)
{
x = 0;
while (x < fdf->map.width)
{
if (y != fdf->map.height - 1)
calc_line_vertical(fdf, y, x);
if (x != fdf->map.width - 1)
calc_line_horizontal(fdf, y, x);
x++;
}
y++;
}
}