-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
87 lines (79 loc) · 2.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhenin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 15:57:44 by mhenin #+# #+# */
/* Updated: 2024/11/29 18:01:13 by mhenin ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static int check_validity(char *str)
{
int i;
i = 0;
while ((str[i] >= '0' && str[i] <= '9') || \
str[i] == '-' || str[i] == '.')
i++;
if (str[i] != '\0')
return (0);
return (1);
}
static void ft_putstr(char *s)
{
int i;
i = 0;
if (!s)
return ;
while (s[i])
i++;
write(1, s, i * sizeof(char));
}
static void setup_mlx(t_var *vars, char *title, double c_x, double c_y)
{
vars->mlx = mlx_init();
if (vars->mlx == NULL)
destroy(vars);
vars->win = mlx_new_window(vars->mlx, WIDTH_LEN, HEIGHT_LEN, title);
if (vars->win == NULL)
destroy(vars);
vars->img.img_ptr = mlx_new_image(vars->mlx, WIDTH_LEN, HEIGHT_LEN);
if (vars->img.img_ptr == NULL)
destroy(vars);
vars->img.img_pixels_ptr = mlx_get_data_addr(vars->img.img_ptr,
&vars->img.bits_per_pixel,
&vars->img.line_len,
&vars->img.endian);
if (vars->img.img_pixels_ptr == NULL)
destroy(vars);
vars->decale.height = 0;
vars->decale.width = 0;
vars->decale.zoom = 200;
vars->c_x = c_x;
vars->c_y = c_y;
}
int main(int ac, char **av)
{
t_var vars;
if (ac == 2 && !ft_strncmp(av[1], "mandelbrot", 10))
{
setup_mlx(&vars, "mandelbrot", 0, 0);
mandelbrot_main(&vars);
}
else if ((ac == 4 && !ft_strncmp(av[1], "julia", 5)) && \
(check_validity(av[2]) && check_validity(av[3])))
{
setup_mlx(&vars, "julia", ft_atoi(av[2]), ft_atoi(av[3]));
julia_main(&vars);
}
else if (ac == 2 && !ft_strncmp(av[1], "burningship", 11))
{
setup_mlx(&vars, "burning ship", 0, 0);
burningship_main(&vars);
}
else
ft_putstr("->'mandelbrot' 'julia <reel> <imaginaire>' 'burningship'");
return (0);
}