6
6
/* By: mbrement <[email protected] > +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2023/02/04 13:20:29 by mbrement #+# #+# */
9
- /* Updated: 2023/02/20 09:54:17 by mbrement ### ########lyon.fr */
9
+ /* Updated: 2023/02/22 06:35:51 by mbrement ### ########lyon.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
@@ -33,6 +33,20 @@ int loop(void *fractal)
33
33
return (0 );
34
34
}
35
35
36
+ void init_img (t_fract * v )
37
+ {
38
+ t_data * i ;
39
+
40
+ i = malloc (sizeof (t_data ));
41
+ i -> bits_per_pixel = 0 ;
42
+ i -> line_length = 0 ;
43
+ i -> endian = 0 ;
44
+ i -> img = mlx_new_image (v -> mlx , WIN_W , WIN_H );
45
+ i -> addr = mlx_get_data_addr (i -> img , & i -> bits_per_pixel ,
46
+ & i -> line_length , & i -> endian );
47
+ v -> data = i ;
48
+ }
49
+
36
50
static struct s_fract fract_compleat_julia (struct s_fract * val )
37
51
{
38
52
val -> x .x = -2 ;
@@ -47,6 +61,7 @@ static struct s_fract fract_compleat_julia(struct s_fract *val)
47
61
val -> zoom_o = val -> zoom - 0.0001 ;
48
62
val -> off_y_o = val -> off_y ;
49
63
val -> off_y_o = val -> off_x ;
64
+ init_img (val );
50
65
return (* val );
51
66
}
52
67
@@ -65,6 +80,7 @@ static struct s_fract fract_compleat_mandelbrot(struct s_fract *val)
65
80
val -> off_y_o = val -> off_y ;
66
81
val -> off_y_o = val -> off_x ;
67
82
val -> zoom_o = val -> zoom - 0.0001 ;
83
+ init_img (val );
68
84
return (* val );
69
85
}
70
86
@@ -74,21 +90,21 @@ void algo_init(int value, int fractal_nb)
74
90
75
91
fractal .value = value ;
76
92
fractal .fractal_nb = fractal_nb ;
77
- if (fractal_nb == 1 )
78
- fractal = fract_compleat_julia (& fractal );
79
- else if (fractal_nb == 2 )
80
- fractal = fract_compleat_mandelbrot (& fractal );
81
- else
82
- fractal = fract_compleat_smandelbrot (& fractal );
83
93
fractal .mlx = mlx_init ();
84
94
if (fractal .mlx == 0 )
85
95
ft_error (4 );
86
96
fractal .window = mlx_new_window (fractal .mlx , WIN_W , WIN_H , "fract_ol" );
87
97
if (fractal .window == 0 )
88
98
ft_error (4 );
99
+ if (fractal_nb == 1 )
100
+ fractal = fract_compleat_julia (& fractal );
101
+ else if (fractal_nb == 2 )
102
+ fractal = fract_compleat_mandelbrot (& fractal );
103
+ else
104
+ fractal = fract_compleat_smandelbrot (& fractal );
105
+ loop (& fractal );
89
106
mlx_hook (fractal .window , 17 , (1L << 5 ), end_of_prog , & fractal );
90
107
mlx_mouse_hook (fractal .window , * hook_mouse , & fractal );
91
108
mlx_key_hook (fractal .window , * hook , & fractal );
92
- loop (& fractal );
93
109
mlx_loop (fractal .mlx );
94
110
}
0 commit comments