aboutsummaryrefslogtreecommitdiff
path: root/include/fractol.h
blob: e315e6bc0d1e84d0a3327300d33b04678ede3cb7 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   fractol.h                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/24 09:28:16 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/24 15:29:50 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef FRACTOL_H
# define FRACTOL_H

# include <unistd.h>
# include <stdlib.h>
# include <stdbool.h>
# include <fcntl.h>
# include <math.h>
# include "mlx.h"
# include "libft.h"
# include "libft_math.h"

# define WINDOW_TITLE "fractol"
# define WINDOW_WIDTH 640
# define WINDOW_HEIGHT 480
# define WINDOW_WIDTH_DOUBLE 640.0
# define WINDOW_HEIGHT_DOUBLE 480.0

# define MLXK_ESC 53
# define MLXK_UP 126
# define MLXK_DOWN 125
# define MLXK_LEFT 123
# define MLXK_RIGHT 124

# define MLX_MOUSE_SCROLL_UP 5
# define MLX_MOUSE_SCROLL_DOWN 4

# define MLX_LITTLE_ENDIAN 0
# define MLX_BIG_ENDIAN 1

# define PALETTE_SIZE 21

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

typedef struct
{
	int				width;
	int				height;
	void			*id;
	char			*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
{
	bool			running;
	bool			updated;
	void			*mlx_ptr;
	void			*window_ptr;
	t_image			window;
	t_color			palette[PALETTE_SIZE];
	t_func_fractal	func;
	t_complex		center;
	t_complex		plane;
	t_complex		julia_const;
}					t_state;

/*
** state.c
*/

int					state_init(t_state *state, char *fractal_name);
int					state_destroy(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 z);
int					julia(t_state *state, t_complex z);

/*
** helper.c
*/

void				h_offset_to_complex(t_state *state, t_complex *z, int offset);

#endif