-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_controls_bonus.c
143 lines (125 loc) · 4.8 KB
/
mouse_controls_bonus.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse_controls_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmustone <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 01:01:19 by vmustone #+# #+# */
/* Updated: 2023/03/23 22:14:18 by vmustone ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void cursor_coordinates(double mouse_x, double mouse_y, t_vars *vars)
{
double midpoint;
mouse_x = vars->minre + (((vars->maxre - vars->minre) / WIDTH) * mouse_x);
mouse_y = vars->maxim - (((vars->maxim - vars->minim) / HEIGHT) * mouse_y);
midpoint = (vars->maxre + vars->minre) / 2.0;
vars->minre += mouse_x - midpoint;
vars->maxre += mouse_x - midpoint;
midpoint = (vars->maxim + vars->minim) / 2.0;
vars->minim += mouse_y - midpoint;
vars->maxim += mouse_y - midpoint;
}
void zoom_in(t_vars *vars)
{
double midpoint;
midpoint = (vars->maxre + vars->minre) / 2.0;
vars->minre = (midpoint + vars->minre) / 2.0;
vars->maxre = (midpoint + vars->maxre) / 2.0;
midpoint = (vars->maxim + vars->minim) / 2.0;
vars->minim = (midpoint + vars->minim) / 2.0;
vars->maxim = (midpoint + vars->maxim) / 2.0;
vars->re_factor = (vars->maxre - vars->minre) / (WIDTH - 1);
vars->im_factor = (vars->maxim - vars->minim) / (HEIGHT - 1);
if (vars->set == JULIA)
draw_julia(vars);
else
draw_mandelbrot(vars);
}
/*
void zoom_in(t_vars *vars)
{
const int num_steps = 10;
int i = 0;
double midpoint_re = (vars->maxre + vars->minre) / 2.0;
double midpoint_im = (vars->maxim + vars->minim) / 2.0;
while (i < num_steps)
{
vars->minre = (midpoint_re + vars->minre) / 2.0;
vars->maxre = (midpoint_re + vars->maxre) / 2.0;
vars->minim = (midpoint_im + vars->minim) / 2.0;
vars->maxim = (midpoint_im + vars->maxim) / 2.0;
vars->re_factor = (vars->maxre - vars->minre) / (WIDTH - 1);
vars->im_factor = (vars->maxim - vars->minim) / (HEIGHT - 1);
i++;
if (vars->set == JULIA)
draw_julia(vars);
else
draw_mandelbrot(vars);
}
}
void zoom_in(t_vars *vars)
{
double zoom_factor = 0.9; // Adjust this value to control the zoom factor
double re_center = (vars->maxre + vars->minre) / 2.0;
double im_center = (vars->maxim + vars->minim) / 2.0;
vars->minre = re_center + (vars->minre - re_center) * zoom_factor;
vars->maxre = re_center + (vars->maxre - re_center) * zoom_factor;
vars->minim = im_center + (vars->minim - im_center) * zoom_factor;
vars->maxim = im_center + (vars->maxim - im_center) * zoom_factor;
vars->re_factor = (vars->maxre - vars->minre) / (WIDTH - 1);
vars->im_factor = (vars->maxim - vars->minim) / (HEIGHT - 1);
if (vars->set == JULIA)
draw_julia(vars);
else
draw_mandelbrot(vars);
}
void zoom_in(t_vars *vars, int x, int y)
{
double zoom_factor = 0.9; // Adjust this value to control the zoom factor
// Calculate the center of the zoom
double re_center = vars->minre + x * vars->re_factor;
double im_center = vars->maxim - y * vars->im_factor;
vars->minre = re_center + (vars->minre - re_center) * zoom_factor;
vars->maxre = re_center + (vars->maxre - re_center) * zoom_factor;
vars->minim = im_center + (vars->minim - im_center) * zoom_factor;
vars->maxim = im_center + (vars->maxim - im_center) * zoom_factor;
vars->re_factor = (vars->maxre - vars->minre) / (WIDTH - 1);
vars->im_factor = (vars->maxim - vars->minim) / (HEIGHT - 1);
if (vars->set == JULIA)
draw_julia(vars);
else
draw_mandelbrot(vars);
}
*/
void zoom_out(t_vars *vars)
{
double re_diff = vars->maxre - vars->minre;
double im_diff = vars->maxim - vars->minim;
vars->minre -= re_diff * 0.2;
vars->maxre += re_diff * 0.2;
vars->minim -= im_diff * 0.2;
vars->maxim += im_diff * 0.2;
vars->re_factor = (vars->maxre - vars->minre) / (WIDTH - 1);
vars->im_factor = (vars->maxim - vars->minim) / (HEIGHT - 1);
if (vars->set == JULIA)
draw_julia(vars);
else
draw_mandelbrot(vars);
}
int mouse_zoom(int button, int x, int y, t_vars *vars)
{
if (button == ON_MOUSEDOWN)
{
cursor_coordinates(x, y, vars);
zoom_in(vars);
}
if (button == ON_MOUSEUP)
{
cursor_coordinates(x, y, vars);
zoom_out(vars);
}
return (0);
}