-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.c
66 lines (59 loc) · 1.95 KB
/
color.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* color.c :+: :+: */
/* +:+ */
/* By: jandre-d <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/03/25 16:00:23 by jandre-d #+# #+# */
/* Updated: 2019/03/30 21:46:25 by jandre-d ######## odam.nl */
/* */
/* ************************************************************************** */
#include "color.h"
#include <math.h>
static void get(double rr, double gg, double bb, uint32_t *to_return)
{
uint8_t r;
uint8_t g;
uint8_t b;
r = rr * 255;
g = gg * 255;
b = bb * 255;
*to_return = ((r << 16) | (g << 8) | b);
}
static void color_from_hsv(uint8_t h, uint8_t s, uint8_t v,
uint32_t *to_return)
{
t_hsv_convert_vars x;
x.s = s / 256.0;
x.v = v / 256.0;
x.h = (h / 256.0) * 6;
x.i = (int)(x.h);
x.f = x.h - x.i;
x.p = x.v * (1 - x.s);
x.q = x.v * (1 - (x.s * x.f));
x.t = x.v * (1 - (x.s * (1 - x.f)));
get(x.v, x.v, x.v, to_return);
if (x.s == 0)
return ;
if (x.i == 0)
get(x.v, x.t, x.p, to_return);
if (x.i == 1)
get(x.q, x.v, x.p, to_return);
if (x.i == 2)
get(x.p, x.v, x.t, to_return);
if (x.i == 3)
get(x.p, x.q, x.v, to_return);
if (x.i == 4)
get(x.t, x.p, x.v, to_return);
if (x.i == 5)
get(x.v, x.p, x.q, to_return);
}
uint32_t get_color_from_iterations(int32_t iter, int32_t max_iter,
int32_t offset)
{
uint32_t to_return;
color_from_hsv((iter + offset) % 256, 255, 255 * (iter < max_iter),
&to_return);
return (to_return);
}