-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_mandelbrot.c
57 lines (53 loc) · 1.9 KB
/
draw_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
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmustone <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/01 12:18:31 by vmustone #+# #+# */
/* Updated: 2023/03/23 15:30:42 by vmustone ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void change_color(t_vars *vars, double c_re, double c_im)
{
vars->z_re = c_re;
vars->z_im = c_im;
vars->iter_count = 0;
while (vars->iter_count < MAX_ITER)
{
vars->z_re2 = vars->z_re * vars->z_re;
vars->z_im2 = vars->z_im * vars->z_im;
if (vars->z_re2 + vars->z_im2 > 4)
break ;
vars->z_im = 2 * vars->z_re * vars->z_im + c_im;
vars->z_re = vars->z_re2 - vars->z_im2 + c_re;
vars->iter_count++;
}
if (vars->iter_count == MAX_ITER)
my_mlx_pixel_put(vars, 0x00000000);
else
my_mlx_pixel_put(vars, (0x00ffff / 0x0ff * 6) * vars->iter_count);
}
static void draw_row(t_vars *vars, double c_im)
{
vars->x = 0;
while (vars->x < WIDTH)
{
vars->c_re = vars->minre + vars->x * vars->re_factor;
change_color(vars, vars->c_re, c_im);
vars->x++;
}
}
void draw_mandelbrot(t_vars *vars)
{
vars->y = 0;
while (vars->y < HEIGHT)
{
vars->c_im = vars->maxim - vars->y * vars->im_factor;
draw_row(vars, vars->c_im);
vars->y++;
}
mlx_put_image_to_window(vars->mlx, vars->win, vars->img, 0, 0);
}