-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfractol.c
More file actions
72 lines (67 loc) · 2.1 KB
/
fractol.c
File metadata and controls
72 lines (67 loc) · 2.1 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zurag <zurag@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 19:31:27 by zurag #+# #+# */
/* Updated: 2021/10/10 19:31:28 by zurag ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void ft_init_fractal_vars(t_vars *mlx)
{
mlx->fractal.new_z_im = 0;
mlx->fractal.new_z_real = 0;
mlx->fractal.old_z_im = 0;
mlx->fractal.old_z_real = 0;
if (mlx->name != 'j')
{
mlx->fractal.const_im = 0;
mlx->fractal.const_real = 0;
}
if (mlx->fractal.flag_j)
{
mlx->fractal.const_im = 0.156;
mlx->fractal.const_real = -0.8;
}
}
void ft_fractal(t_vars *mlx)
{
int x;
int y;
int i;
x = 0;
y = 0;
i = 0;
ft_init_fractal_vars(mlx);
mlx->img = mlx_new_image(mlx->mlx, WIDHT, HEIGHT);
mlx->addr = mlx_get_data_addr(mlx->img, &(mlx->bits_per_pixel), \
&(mlx->line_length), & (mlx->endian));
while (y < HEIGHT)
{
while (x < WIDHT)
{
i = ft_launch_fractal(mlx, x, y);
my_mlx_pixel_put(mlx, x, y, ft_create_color(i, mlx));
i = 0;
x++;
}
y++;
x = 0;
}
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 0, 0);
mlx_destroy_image(mlx->mlx, mlx->img);
}
int ft_launch_fractal(t_vars *vars_mlx, int x, int y)
{
if (vars_mlx->name == 'j')
return (ft_julia(&vars_mlx->fractal, x, y));
else if (vars_mlx->name == 'm')
return (ft_mandelbrot(&vars_mlx->fractal, x, y));
else if (vars_mlx->name == 'b')
return (ft_burning_ship(&vars_mlx->fractal, x, y));
else
return (-1);
}