-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
106 lines (100 loc) · 2.73 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmack <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/30 07:40:42 by tmack #+# #+# */
/* Updated: 2016/10/05 07:40:03 by tmack ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
#include <math.h>
void init_mandle(t_frac *m)
{
m->s_x_max = 800;
m->s_y_max = 600;
m->w_x_min = -2.50;
m->w_x_max = 2.00;
m->w_y_min = -2.00;
m->w_y_max = 4.00;
m->iterate_max = 200;
m->e_rad = 2.00;
m->e_rad2 = m->e_rad * m->e_rad;
}
void init_julia(t_frac *m)
{
m->w_x_min = -0.7;
m->w_x_max = 0.27015;
m->s_x_max = 800;
m->s_y_max = 600;
m->w_y_min = -2.00;
m->w_y_max = 4.00;
m->iterate_max = 200;
m->e_rad = 2.00;
m->e_rad2 = m->e_rad * m->e_rad;
}
void chose_fractal(t_frac *m)
{
if (ft_strcmp(m->argv, "mandelbrot") == 0)
{
if (m->img != NULL)
mlx_destroy_image(m->init, m->img);
mandelbrot(m);
}
else if (ft_strcmp(m->argv, "julia") == 0)
{
if (m->img != NULL)
mlx_destroy_image(m->init, m->img);
julia(m);
}
else if (ft_strcmp(m->argv, "mandelbrot_three") == 0)
{
if (m->img != NULL)
mlx_destroy_image(m->init, m->img);
mandelbrot_three(m);
}
else
{
ft_putstr("error: invalid argument! please enter: ");
ft_putstr("mandelbrot | julia | mandelbrot_three \n");
exit(0);
}
}
void main_init(t_frac *win, char **argv)
{
win->m_x = 0;
win->m_y = 0;
win->zoom = 1;
win->pan_y = 0;
win->pan_x = 0;
win->size = 0;
win->bpp = 0;
win->end = 0;
win->argv = strdup(argv[1]);
win->data = NULL;
win->init = mlx_init();
win->win = mlx_new_window(win->init, 800, 600, "fractol");
chose_fractal(win);
mlx_expose_hook(win->win, expose, win);
mlx_key_hook(win->win, key_hook, win);
mlx_mouse_hook(win->win, mouse_hook, win);
mlx_hook(win->win, 6, (1L << 6), mouse_move, win);
mlx_loop(win->init);
}
int main(int argc, char **argv)
{
t_frac m;
if (argc == 2)
{
if (ft_strcmp(argv[1], "julia") == 0)
init_julia(&m);
else if (ft_strcmp(argv[1], "mandelbrot") == 0)
init_mandle(&m);
else if (ft_strcmp(argv[1], "mandelbrot_three") == 0)
init_mandle(&m);
main_init(&m, argv);
}
return (0);
}