-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.c
96 lines (87 loc) · 2.31 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/19 20:12:39 by jjacobso #+# #+# */
/* Updated: 2019/05/21 21:42:10 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int is_hex_clr(char *s)
{
int i;
if (!s)
return (0);
i = 0;
while (i < 6)
{
if (!s[i] || !(ft_isdigit(s[i]) || ft_isalpha(s[i])))
return (0);
i++;
}
return (1);
}
int str_to_clr(char *s)
{
if (!s)
return (0);
if (s[0] == '0' && s[1] == 'x')
s += 2;
else
error("Invalid map");
if (!is_hex_clr(s))
error("Invalid map");
return (ft_atoibase(s, 16));
}
int rgb(int r, int g, int b)
{
return (r << 16 | g << 8 | b);
}
static double get_lvl(t_list *z, double border, int w, int size)
{
int i;
double res;
i = 1;
while (z)
{
if (w == *(int *)z->data)
{
res = (double)i / size;
if (res < border)
return (border);
return (res);
}
z = z->next;
i++;
}
ft_printf("ERROR\n");
exit(-1);
}
void set_line_color(t_view *view)
{
t_list *z;
int i;
int j;
int size;
z = get_z_lvls(view);
size = l_size(z);
i = -1;
while (++i < MAP.max_y && (j = -1))
while (++j < MAP.max_x)
{
if (PROPS.brightness < 0)
PROJECTION(i, j).clr = darker(DOT(i, j).clr ? DOT(i, j).clr
: PROPS.line_clr, ((double)ABS(PROPS.brightness)) / 100);
else
PROJECTION(i, j).clr = brighter(DOT(i, j).clr ? DOT(i, j).clr
: PROPS.line_clr, (double)PROPS.brightness / 100);
PROJECTION(i, j).clr = intensity(PROJECTION(i, j).clr, 0,
OPTIONS.interpolation ?
get_lvl(z, (double)PROPS.darkness_border / 100,
DOT(i, j).w, size) : 1, 0);
}
l_destroy(&z);
}