-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfractol.h
206 lines (176 loc) · 4.79 KB
/
fractol.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: znichola <znichola@student.42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/26 18:30:39 by znichola #+# #+# */
/* Updated: 2022/12/01 18:41:00 by znichola ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FRACTOL_H
# define FRACTOL_H
# include <stdio.h> // strerror perror
# include <unistd.h>
# include <stdlib.h> // malloc exit
# include <math.h>
# include <complex.h>
# include "mlx.h"
# include "defines.h"
# include "colours.h"
typedef struct s_ipoint
{
int x;
int y;
} t_ipoint;
typedef struct s_fpoint
{
double x;
double y;
} t_fpoint;
typedef struct s_pallet
{
int len;
int c[16];
} t_pallet;
typedef struct s_pallets
{
t_pallet p[10];
} t_pallets;
// typedef struct s_app
// {
// t_data data;
// void *mlx;
// void *mlx_win;
// t_ipoint mouse;
// t_ipoint mouse_left;
// t_ipoint mouse_right;
// t_ipoint center;
// t_fpoint scale;
// t_fpoint offset;
// } t_app;
/* actually used */
typedef struct s_complex
{
double a;
double b;
} t_complex;
/* holds frame information
* to print to screen */
typedef struct s_data
{
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
int width;
int hight;
} t_data;
/* event system */
typedef struct s_vars
{
void *mlx;
void *win;
} t_vars;
// void *mlx; // factor out this usless thing
/* scalling the complex number
* filed to the screen space */
typedef struct s_cmpx_fld
{
double scale;
double a_min;
double a_max;
double b_min;
double b_max;
int depth;
} t_cmpx_fld;
/* struc to hold app information */
typedef struct s_app
{
t_data img;
t_vars vars;
t_cmpx_fld cf;
t_ipoint mouse;
t_ipoint mouse_down;
t_fpoint world_mouse_right;
int mouse_right_toggle;
int mouse_left_toggle;
t_fpoint offset;
t_fpoint scale;
t_ipoint points[MAXPOINTS];
int render;
t_pallets pallets;
int pallet_index;
int start_depth;
int fractal_select;
} t_app;
/* comlplex.c */
t_complex c_addition(t_complex c1, t_complex c2);
t_complex c_multiplication(t_complex c1, t_complex c2);
t_complex c_power2(t_complex c1);
double c_length(t_complex c);
t_complex c_abs(t_complex c1);
/* map */
t_ipoint rworld_to_screen(t_app *a, t_fpoint w);
t_fpoint rscreen_to_world(t_app *a, t_ipoint s);
/* init */
void init_app(t_app *p);
void set_scale_offset(t_app *p);
/* display */
void my_mlx_pixel_put(t_data *data, int x, int y, int color);
int render_next_frame(t_app *p);
void put_circle_fast(t_data *d, int r, t_ipoint center, int colour);
/* display itterators */
int mandelbrot_itterations(t_app *p);
int julia_itterations(t_app *p);
int burningship_itterations(t_app *p);
int burningjulia_itterations(t_app *p);
int display_itterations(t_app *p);
/* events */
int destroy(t_vars *vars);
int mouse_hook(int action, int x, int y, t_app *a);
int mouse_move(int x, int y, t_app *a);
void zoom(t_app *a, int dir);
/* events 2 */
int key_press(int keycode, t_app *a);
/* fractal */
int mandelbrot_like(t_complex z, t_complex c, int depth);
int generate_fractal(t_app *p);
int fractal_selector(t_app *a, t_ipoint pix, int fractal, int depth);
/* converter */
t_complex ftc(t_fpoint f);
t_fpoint ctf(t_complex c);
t_fpoint fpoint(double x, double y);
t_ipoint ipoint(int x, int y);
int toggle(int a);
/* debug */ // they use printf need to remove after
void pi(t_ipoint p);
void pf(t_fpoint p);
void print_complex(char *s, t_complex c);
// ----- COLOUR ----- //
// colours
int create_trgb(int t, int r, int g, int b);
int get_t(int trgb);
int get_r(int trgb);
int get_g(int trgb);
int get_b(int trgb);
// colours funcs
int colour_lerp(int min, int max, int point);
int colour_ramp(int min, int max, int point, t_pallet p);
void init_pallets(t_pallets *p);
int colour_shades(int colour, int depth, t_cmpx_fld *cf);
// colours init 1
t_pallet clpt_greyscale(void);
t_pallet clpt_pollen(void);
t_pallet clpt_full_rainbow(void);
t_pallet clpt_twilight(void);
t_pallet clpt_blue_to_pink(void);
// colours init 2
t_pallet clpt_green_to_red(void);
t_pallet clpt_pastel_shades(void);
t_pallet clpt_retroearth(void);
t_pallet clpt_fading(void);
t_pallet clpt_cyberneon(void);
#endif /* fractol.h */