-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot.c
53 lines (50 loc) · 2.11 KB
/
mandelbrot.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsivanat <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/23 16:14:43 by vsivanat #+# #+# */
/* Updated: 2024/04/11 17:56:42 by vsivanat ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void loop_img_mandelbrot(t_master *master)
{
master->fract->x = -1;
while (++(master->fract->x) < WINDOW_X)
{
master->fract->y = -1;
while (++(master->fract->y) < WINDOW_Y)
mandelbrot(master);
}
}
void mandelbrot(t_master *master)
{
clear_px(master);
master->px->b = (((WINDOW_Y / -2) + master->fract->y) / master->scale)
+ master->fract->horizontal_shift;
master->px->a = (((WINDOW_X / -2) + master->fract->x) / master->scale)
+ master->fract->vertical_shift - 0.5;
master->px->ca = master->px->a;
master->px->cb = master->px->b;
while (master->px->i < master->iterations)
{
master->px->aa = master->px->a * master->px->a - master->px->b
* master->px->b;
master->px->bb = 2 * master->px->a * master->px->b;
master->px->a = master->px->aa + master->px->ca;
master->px->b = master->px->bb + master->px->cb;
if ((master->px->a * master->px->a + master->px->b
* master->px->b) > 16)
break ;
master->px->i++;
}
if (master->px->i == master->iterations || master->px->i == 0)
mlx_put_pixel(master->img, master->fract->x, master->fract->y,
get_grey(0, 255));
else if (master->px->i > 0)
mlx_put_pixel(master->img, master->fract->x, master->fract->y,
get_rgb_a(master->px->i, 255, master));
}