-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburningship.c
99 lines (92 loc) · 2.92 KB
/
burningship.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* burningship.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhenin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 16:29:20 by mhenin #+# #+# */
/* Updated: 2024/11/29 16:33:30 by mhenin ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
#include <mlx.h>
#include <unistd.h>
static void render_burningship(t_var *data)
{
int i;
int j;
int iterations;
i = 0;
while (i < HEIGHT_LEN)
{
j = 0;
while (j < WIDTH_LEN)
{
iterations = in_burningship((j - WIDTH_LEN / 2 + \
data->decale.width) / data->decale.zoom,
(i - HEIGHT_LEN / 2 + data->decale.height) \
/ data->decale.zoom);
if (iterations == 0)
my_pixel_put(&data->img, j, i, 0x000000);
else
my_pixel_put(&data->img, j, i, \
get_color(iterations));
j++;
}
i++;
}
}
static int mouse_hook(int keysym, int x, int y, t_var *data)
{
double old_zoom;
double new_zoom;
double zoom_factor;
old_zoom = data->decale.zoom;
if (keysym == 4)
data->decale.zoom *= 1.5;
else if (keysym == 5)
data->decale.zoom /= 1.5;
if (keysym == 4 || keysym == 5)
{
new_zoom = data->decale.zoom;
zoom_factor = (double)new_zoom / (double)old_zoom;
data->decale.width = (data->decale.width + x - WIDTH_LEN / 2) \
* zoom_factor - (x - WIDTH_LEN / 2);
data->decale.height = (data->decale.height + y - HEIGHT_LEN / 2) \
* zoom_factor - (y - HEIGHT_LEN / 2);
render_burningship(data);
mlx_put_image_to_window(data->mlx, data->win, data->img.img_ptr, 0, 0);
}
return (0);
}
static int f(int keysym, t_var *data)
{
if (keysym == XK_Up)
data->decale.height += -200;
else if (keysym == XK_Down)
data->decale.height += 200;
else if (keysym == XK_Left)
data->decale.width += -200;
else if (keysym == XK_Right)
data->decale.width += 200;
else if (keysym == XK_Escape)
destroy(data);
if (keysym == XK_Up || keysym == XK_Down
|| keysym == XK_Left || keysym == XK_Right)
{
render_burningship(data);
mlx_put_image_to_window(data->mlx, data->win, data->img.img_ptr, 0, 0);
}
return (0);
}
int burningship_main(t_var *vars)
{
render_burningship(vars);
mlx_put_image_to_window(vars->mlx, vars->win, vars->img.img_ptr, 0, 0);
mlx_key_hook(vars->win, f, vars);
mlx_hook(vars->win, 17, 0, destroy, vars);
mlx_mouse_hook(vars->win, mouse_hook, vars);
mlx_loop(vars->mlx);
return (0);
}