aboutsummaryrefslogtreecommitdiff
path: root/include/fractol.h
blob: 80696d3d52f881d50b639dbc6325852b03fb2777 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   fractol.h                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/24 09:28:16 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/27 13:39:08 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef FRACTOL_H
# define FRACTOL_H

# include <unistd.h>
# include <stdlib.h>
# include <stdbool.h>
# include <stdint.h>
# include <fcntl.h>
# include <math.h>
# include <pthread.h>

# include "mlx.h"
# include "libft.h"
# include "libft_math.h"

# define WINDOW_TITLE "fractol"

# define FRACTOL_RESOLUTION_LOW

# ifdef FRACTOL_RESOLUTION_HIGH
#  define WINDOW_WIDTH 1600
#  define WINDOW_HEIGHT 1200
#  define FWINDOW_WIDTH 1600.0
#  define FWINDOW_HEIGHT 1200.0
# elif defined(FRACTOL_RESOLUTION_MEDIUM)
#  define WINDOW_WIDTH 1024
#  define WINDOW_HEIGHT 768
#  define FWINDOW_WIDTH 1024.0
#  define FWINDOW_HEIGHT 768.0
# else
#  define FRACTOL_RESOLUTION_LOW
#  define WINDOW_WIDTH 800
#  define WINDOW_HEIGHT 600
#  define FWINDOW_WIDTH 800.0
#  define FWINDOW_HEIGHT 600.0
# endif
// # define WINDOW_WIDTH_DOUBLE 640.0
// # define WINDOW_HEIGHT_DOUBLE 480.0

# define MLXK_ESC 65307
# define MLXK_UP 65289
# define MLXK_DOWN 65362
# define MLXK_LEFT 65364
# define MLXK_RIGHT 65361
# define MLXK_H 104
# define MLXK_J 106
# define MLXK_K 107
# define MLXK_L 108
# define MLXK_D 100
# define MLXK_F 102
# define MLXK_S 115
# define MLXK_E 101
# define MLXK_R 114
# define MLXK_C 99
# define MLXK_PLUS 61
# define MLXK_MINUS 45

# define MLX_MOUSE_SCROLL_UP 5
# define MLX_MOUSE_SCROLL_DOWN 4
# define MLX_MOUSE_LEFT 1

# define MLX_LITTLE_ENDIAN 0
# define MLX_BIG_ENDIAN 1

# define ZOOM_SPEED 1.2

typedef union
{
	unsigned int	hexcode;
	struct
	{
		uint8_t		b;
		uint8_t		g;
		uint8_t		r;
		uint8_t		alpha;
	}				rgb;
}					t_color;

typedef struct
{
	uint8_t			h;
	uint8_t			s;
	uint8_t			l;
}					t_color_hsl;

typedef struct
{
	int				width;
	int				height;
	void			*id;
	t_color			*data;
	int				depth;
	int				size_line;
	int				endian;
}					t_image;

typedef struct
{
	double			r;
	double			i;
}					t_complex;

struct				s_state;

typedef int			(*t_func_fractal)(struct s_state *state, t_complex z);

typedef struct		s_state
{
	t_func_fractal	func;
	t_color			*palette;
	t_image			window;
	t_complex		c;
	bool			running;
	bool			updated;
	void			*mlx_ptr;
	void			*window_ptr;
	t_complex		center;
	t_complex		plane;
	int				iterations;
	int				offsets[WINDOW_HEIGHT];
	double			samples;
}					t_state;

typedef struct
{
	double			z_i;
	double			step_i;
	int				offset;
	t_state			*state;
}					t_render_routine_arg;

/*
** state.c
*/

int					state_init(t_state *state, char *fractal_name);
int					state_destroy(t_state *state);
void 				state_update_palette(t_state *state);
void				state_shift_palette(t_state *state);

/*
** render.c
*/

int					render_update(t_state *state);

/*
** event.c
*/

int					event_quit(t_state *state);
int					event_keydown(int key, t_state *state);
int					event_mouse(int button, int x, int y, t_state *state);
int					event_mouse_motion(int x, int y, t_state *state);

/*
** fractals/
*/

int					mandelbrot(t_state *state, t_complex c);
int					julia(t_state *state, t_complex c);
int					tricorn(t_state *state, t_complex c);
int					burningship(t_state *state, t_complex c);

/*
** helper.c
*/

void				h_zoom_in(t_state *state);
void				h_zoom_out(t_state *state);

/*
** color.c
*/

t_color_hsl			color_rgb_to_hsl(t_color color_rgb);
t_color				color_hsl_to_rgb(t_color_hsl color_hsl);

/*
** capture.c
*/

int		capture(t_state *state, char *filename);

#endif