-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_2.c
55 lines (50 loc) · 2.3 KB
/
events_2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* events_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 17:39:48 by amacarul #+# #+# */
/* Updated: 2024/11/11 17:39:51 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libfractol.h"
/*Zooms in on a fractal, centering on the mouse position.
- Gets the current mouse position in the window.
- Converts the mouse coordinates to corresponding coordinates
in the complex plane (mouse_cx, mouse_cy).
- Adjusts the visible area (min_x, max_x, min_y, max_y)
of the fractal based on the mouse position and zoom factor.
- Redraws the fractal.
*/
void fct_zoom(t_fractol *f, double zoom_factor)
{
int32_t mouse_x;
int32_t mouse_y;
double mouse_cx;
double mouse_cy;
mlx_get_mouse_pos(f->mlx, &mouse_x, &mouse_y);
mouse_cx = f->min_x + (f->max_x - f->min_x) * (mouse_x / (double)WIDTH);
mouse_cy = f->min_y + (f->max_y - f->min_y) * (mouse_y / (double)HEIGHT);
f->min_x = mouse_cx - (mouse_cx - f->min_x) / zoom_factor;
f->max_x = mouse_cx + (f->max_x - mouse_cx) / zoom_factor;
f->min_y = mouse_cy - (mouse_cy - f->min_y) / zoom_factor;
f->max_y = mouse_cy + (f->max_y - mouse_cy) / zoom_factor;
fct_draw_fractal(f);
}
/*Selects the next palette of colors*/
void fct_change_color(t_fractol *f)
{
f->palette_index = (f->palette_index + 1) % 3;
ft_printf("showing palette num: %i\n", f->palette_index);
fct_draw_fractal(f);
}
/*Selects the next pattern from the Julia set*/
void fct_change_julia(t_fractol *f)
{
f->pattern_index = (f->pattern_index + 1) % 7;
fct_set_julia_pattern(f, f->patterns[f->pattern_index].name);
ft_printf("showing %s\n", f->patterns[f->pattern_index].name);
fct_draw_fractal(f);
}