-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.c
80 lines (72 loc) · 1.64 KB
/
colors.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
77
78
79
80
#include "includes/fractol.h"
static int set_colorset_galactic(int iteration, int max_iteration)
{
double t;
int red;
int green;
int blue;
if (iteration >= max_iteration)
{
red = 30;
green = 0;
blue = 0;
}
else
{
t = (double)iteration / (double)(1 + max_iteration);
red = (int)(9 * (1 - t) * pow(t, 3) * 255);
green = (int)(15 * pow((1 - t), 2) * pow(t, 2) * 255);
blue = (int)(8.5 * pow((1 - t), 3) * t * 255);
}
return (((red & 0xFF) << 16) + ((green & 0xFF) << 8) + (blue & 0xFF));
}
static int set_colorset_red(int iteration, int max_iteration)
{
int red;
int green;
int blue;
if (iteration >= max_iteration)
{
red = 141;
green = 26;
blue = 187;
}
else
{
red = (iteration * 12) % 255;
green = (iteration * 0) % 255;
blue = (iteration * 6) % 255;
}
return (((red & 0xFF) << 16) + ((green & 0xFF) << 8) + (blue & 0xFF));
}
static int set_colorset_psycho(int iteration, int max_iteration)
{
int red;
int green;
int blue;
if (iteration >= max_iteration)
{
red = 20;
green = 0;
blue = 80;
}
else
{
red = (iteration * 128) % 255;
green = (iteration * 255) % 255;
blue = (iteration * 64) % 255;
}
return (((red & 0xFF) << 16) + ((green & 0xFF) << 8) + (blue & 0xFF));
}
int get_color(t_fractal *fractal, int iteration, int max_iteration)
{
int color;
color = 0;
if (fractal->colorset == COLORSET_GALACTIC)
color = set_colorset_galactic(iteration, max_iteration);
else if (fractal->colorset == COLORSET_RED)
color = set_colorset_red(iteration, max_iteration);
else if (fractal->colorset == COLORSET_PSYCHO)
color = set_colorset_psycho(iteration, max_iteration);
return (color);
}