-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
70 lines (63 loc) · 2.02 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yagnaou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/02 16:30:19 by yagnaou #+# #+# */
/* Updated: 2022/03/09 17:34:27 by yagnaou ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void hooks(t_p *p)
{
mlx_key_hook(p->win, arrow_move, p);
mlx_hook(p->win, 17, 0, exit_when_close, p);
mlx_mouse_hook(p->win, zoom, p);
}
void create_window(t_p *p)
{
p->ptr = mlx_init();
p->win = mlx_new_window(p->ptr, WIN_SIZE, WIN_SIZE, "fract-ol");
}
void create_image(t_p *p)
{
p->img = mlx_new_image(p->ptr, WIN_SIZE, WIN_SIZE);
p->addr = mlx_get_data_addr(p->img, &p->bits_per_pixel,
&p->line_length, &p->endian);
}
void choose_fractale(char *av, t_p *p)
{
if (!ft_strcmp(av, "julia") || !ft_strcmp(av, "first_julia")
|| !ft_strcmp(av, "second_julia"))
{
julia(av, p);
p->fractal = ft_strdup(av);
}
else if (!ft_strcmp(av, "mandelbrot"))
{
mandelbrot(p);
p->fractal = ft_strdup("mandelbrot");
}
else if (!ft_strcmp(av, "burning_ship"))
{
burning_ship(p);
p->fractal = ft_strdup("burning_ship");
}
mlx_put_image_to_window(p->ptr, p->win, p->img, 0, 0);
}
int main(int ac, char **av)
{
t_p *p;
p = malloc(sizeof(t_p));
p->zoom = 4.0;
create_window(p);
create_image(p);
if (ac != 2 || available_fractals(av))
error_phrase();
choose_fractale(av[1], p);
hooks(p);
mlx_loop(p->ptr);
return (0);
}