-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.c
69 lines (64 loc) · 2.1 KB
/
hooks.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysingh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 21:36:41 by ysingh #+# #+# */
/* Updated: 2022/12/09 14:52:30 by ysingh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void hook(struct mlx_key_data keydata, void *param)
{
t_data *data;
data = (t_data *)param;
if (keydata.key == MLX_KEY_ESCAPE)
{
mlx_terminate(data->mlx);
exit(EXIT_SUCCESS);
}
if (keydata.action == MLX_RELEASE)
{
if (keydata.key == MLX_KEY_UP)
data->y_y -= 0.50;
if (keydata.key == MLX_KEY_DOWN)
data->y_y += 0.50;
if (keydata.key == MLX_KEY_LEFT)
data->x_x -= 0.50;
if (keydata.key == MLX_KEY_RIGHT)
data->x_x += 0.50;
ft_color_hook(keydata, data);
if (data->fractal == 0)
hook_move(keydata, data);
ft_draw_fractal(data);
}
}
void ft_color_hook(struct mlx_key_data keydata, t_data *data)
{
if (keydata.key == MLX_KEY_P)
data->max_iter += 10;
if (keydata.key == MLX_KEY_L)
data->max_iter -= 10;
if (keydata.key == MLX_KEY_N)
{
data->hue_off = 0.;
data->rainbow = 0;
}
if (keydata.key == MLX_KEY_M)
data->rainbow = !data->rainbow;
}
void hook_move(struct mlx_key_data keydata, t_data *data)
{
if (keydata.key == MLX_KEY_Y)
data->v2 += 0.01f;
if (keydata.key == MLX_KEY_H)
data->v2 -= 0.01f;
if (keydata.key == MLX_KEY_G)
data->v1 += 0.01f;
if (keydata.key == MLX_KEY_T)
data->v1 -= 0.01f;
free(data->complex);
data->complex = ft_create_complex(data->v1, data->v2);
}