-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.c
76 lines (66 loc) · 2.44 KB
/
render.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmiyakaw <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 14:22:34 by gmiyakaw #+# #+# */
/* Updated: 2022/12/20 14:51:59 by gmiyakaw ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
// checks for the correct argument and sets f->set to the chosen
// fractal. If no avaiable option is given, displays an error
// message and exits cleanly.
void sort_fractal(t_data *f, char *arg)
{
arg = ft_str_tolower(arg);
if (ft_strcmp(arg, "mandelbrot") == 0)
f->set = MANDELBROT;
else if (ft_strcmp(arg, "julia") == 0)
f->set = JULIA;
else
{
ft_printf("Error: no such fractal\n");
ft_printf("Available fractals: Mandelbrot, Julia\n");
clean_exit(f);
}
return ;
}
// "listens" for events, generates a fractal based on the
// value of f->set
int generate_fractal(t_data *f)
{
handle_events(f);
if (f->set == MANDELBROT)
gen_mandelbrot(f);
if (f->set == JULIA)
gen_julia(f);
return (0);
}
// bit shifts the ints into the correct position for color coding
// bits for color are coded: TTT RRR GGG BBB
// ranging from 000 to 255
int create_trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}
// gets the color values of r g b. Uses count as a
// way to set where in the spectrum each primary color should
// land. Count if multiplied so it accounts for greater range
// 15 is an arbritary value that can be changed if more less
// range is desired.
// The function then applies any color shift and assembles
// the int using create_trgb.
int make_color(t_data *f)
{
int color_value;
color_value = f->count * 15;
f->color->r = get_red(color_value);
f->color->g = get_green(color_value);
f->color->b = get_blue(color_value);
apply_shift(f);
return (create_trgb(0, f->color->r, f->color->g, \
f->color->b));
}