-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_and_color.c
44 lines (38 loc) · 1.59 KB
/
draw_and_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_and_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbaela <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 10:01:28 by lbaela #+# #+# */
/* Updated: 2021/10/27 11:54:11 by lbaela ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
double find_percent(int start, int end, int current)
{
double placement;
double distance;
if (current == start)
return (0.0);
placement = current - start;
distance = end - start;
if (distance == 0)
return (1.0);
return (placement / distance);
}
static int get_tint(int start, int end, double percentage)
{
return ((int)((1 - percentage) * start + percentage * end));
}
int get_grad_color(int start, int end, double percentage)
{
int red;
int green;
int blue;
red = get_tint((start >> 16) & 0xFF, (end >> 16) & 0xFF, percentage);
green = get_tint((start >> 8) & 0xFF, (end >> 8) & 0xFF, percentage);
blue = get_tint(start & 0xFF, end & 0xFF, percentage);
return ((red << 16) | (green << 8) | blue);
}