-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol_bonus.c
95 lines (88 loc) · 3.09 KB
/
fractol_bonus.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
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cnascime <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 07:58:06 by cnascime #+# #+# */
/* Updated: 2023/03/20 18:06:24 by cnascime ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol_bonus.h"
void guide(void);
void load(t_setup *ol);
int eject(t_setup *ol);
int main(int argc, char **argv)
{
t_setup ol;
char *type;
type = argv[argc - 1];
if (argc == 2)
{
ft_strtolower(type);
ol.type = type;
load(&ol);
render(&ol);
mlx_hook(ol.window, 17, 0, eject, &ol);
mlx_key_hook(ol.window, &keypress, &ol);
mlx_mouse_hook(ol.window, &buttonpress, &ol);
mlx_loop(ol.mlx);
}
else
guide();
return (0);
}
// Since I am using a method to reset the fractal by pressing the middle button,
// I had to implement more verifications other than argc == 2, because my reset
// function passes argc = 1 and the type of the fractal only.
// Initialises the connector and some variables of the struct.
void load(t_setup *ol)
{
ol->mlx = mlx_init();
if (!ol->mlx)
eject(ol);
ol->window = mlx_new_window(ol->mlx, WINDOWWIDTH, WINDOWHEIGHT, "fract'ol");
if (!ol->window)
{
free(ol->window);
eject(ol);
}
ol->image = mlx_new_image(ol->mlx, WINDOWWIDTH, WINDOWHEIGHT);
ol->address = mlx_get_data_addr(ol->image, &ol->bitsperpixel,
&ol->linelength, &ol->endian);
ol->minreal = -2.0;
ol->maxreal = 2.0;
ol->medreal = (ol->maxreal - ol->minreal);
ol->minimag = -2.0;
ol->maximag = 2.0;
ol->palette = 0;
palette(ol);
}
// Calls for the specific fractal function according to the user's parameters.
double fractal(t_setup *ol)
{
double creal;
double cimag;
creal = ol->minreal + ol->x * (ol->maxreal - ol->minreal) / WINDOWWIDTH;
cimag = ol->maximag + ol->y * (ol->minimag - ol->maximag) / WINDOWHEIGHT;
if (ft_strcmp(ol->type, "mandelbrot") == 0)
return (mandelbrot(ol, creal, cimag));
else if (ft_strcmp(ol->type, "julia1") == 0)
return (julia1(ol, creal, cimag));
else if (ft_strcmp(ol->type, "julia2") == 0)
return (julia2(ol, creal, cimag));
else if (ft_strcmp(ol->type, "julia3") == 0)
return (julia3(ol, creal, cimag));
else if (ft_strcmp(ol->type, "julia4") == 0)
return (julia4(ol, creal, cimag));
else if (ft_strcmp(ol->type, "julia5") == 0)
return (julia5(ol, creal, cimag));
else if (ft_strcmp(ol->type, "tricorn") == 0)
return (tricorn(ol, creal, cimag));
else if (ft_strcmp(ol->type, "burningship") == 0)
return (burningship(ol, creal, cimag));
else
guide();
return (0);
}