-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolor lerp.cs
More file actions
37 lines (37 loc) · 776 Bytes
/
Copy pathcolor lerp.cs
File metadata and controls
37 lines (37 loc) · 776 Bytes
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
public List<Color> ColorLerp(Color a, Color b)
{
List<Color> output = new List<Color>();
output.Add(a);
//get changes in r, g, and b
int cr = a.R - b.R;
int cg = a.G - b.G;
int cb = a.B - b.B;
//average out differences
int av = (cr + cg + cb) / 3;
//proportions to prepare for lerping
//1/(change) = x/(average)
//cross multiply and divide
/*
Ex:
1 x
--- = ---
cr av
So...
pr = crx = av
pr = av/cr
*/
int pr = av/cr;
int pg = av/cg;
int pb = av/cb;
//slope = cy / cx
//cy = cr/cg/cb
//cx = av
//slope cr/cg/cb/av
for (int i = 0; i != av)
{
//lerp!
output.Add(new Color(/*R*/ cr > 0 ? a.R + cr/av : a.R - cr/av, /*G*/ cg > 0 ? a.G + cg/av : a.G - cg/av, /*B*/ cb > 0 ? a.B + cb/av : a.B - cb/av));
}
output.Add(b);
return output;
}