-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskitlz_to_map.c
More file actions
85 lines (75 loc) · 2.34 KB
/
skitlz_to_map.c
File metadata and controls
85 lines (75 loc) · 2.34 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* skitlz_to_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgerda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/23 17:46:36 by bgerda #+# #+# */
/* Updated: 2019/11/23 17:48:55 by bgerda ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int first_color(int z, int max_z, int min_z)
{
double part;
part = percent(min_z, max_z, z);
if (part < 0.2)
return (0x006400);
else if (part < 0.4)
return (0x00BFFF);
else if (part < 0.6)
return (0x8B008B);
else if (part < 0.8)
return (0xFFFF00);
else
return (0xFF0000);
}
double percent(int start, int end, int current)
{
double placement;
double distance;
placement = current - start;
distance = end - start;
return ((distance == 0) ? 1.0 : (placement / distance));
}
int get_light(int start, int end, double percentage)
{
return ((int)((1 - percentage) * start + percentage * end));
}
int get_color(t_pix present, t_pix start, t_pix end, t_pix delta)
{
int red;
int green;
int blue;
double percentage;
if (present.color == end.color)
return (present.color);
if (delta.x > delta.y)
percentage = percent(start.x, end.x, present.x);
else
percentage = percent(start.y, end.y, present.y);
red = get_light((start.color >> 16) & 0xFF, (end.color >> 16)
& 0xFF, percentage);
green = get_light((start.color >> 8) & 0xFF, (end.color >> 8)
& 0xFF, percentage);
blue = get_light(start.color & 0xFF, end.color & 0xFF, percentage);
return ((red << 16) | (green << 8) | blue);
}
void make_first_color(int ****axis, int min, int max)
{
int ***spl;
int x;
int y;
y = -1;
spl = *axis;
while (spl[++y])
{
x = -1;
while (spl[y][++x])
{
if (spl[y][x][1] == 0)
spl[y][x][1] = first_color(spl[y][x][0], max, min);
}
}
}