-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateColorRamp.js
30 lines (26 loc) · 1 KB
/
generateColorRamp.js
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
function interpolate(pBegin, pEnd, pStep, pMax) {
if (pBegin < pEnd) {
return ((pEnd - pBegin) * (pStep / pMax)) + pBegin;
} else {
return ((pBegin - pEnd) * (1 - (pStep / pMax))) + pEnd;
}
}
function generateColor(theColorBegin, theColorEnd, theNumSteps) {
var colorArray = new Array();
theColorBegin = parseInt(theColorBegin, 16);
theColorEnd = parseInt(theColorEnd, 16);
theR0 = (theColorBegin & 0xff0000) >> 16;
theG0 = (theColorBegin & 0x00ff00) >> 8;
theB0 = (theColorBegin & 0x0000ff) >> 0;
theR1 = (theColorEnd & 0xff0000) >> 16;
theG1 = (theColorEnd & 0x00ff00) >> 8;
theB1 = (theColorEnd & 0x0000ff) >> 0;
for (i = 0; i <= theNumSteps; i++) {
theR = interpolate(theR0, theR1, i, theNumSteps);
theG = interpolate(theG0, theG1, i, theNumSteps);
theB = interpolate(theB0, theB1, i, theNumSteps);
theVal = (((theR << 8) | theG) << 8) | theB;
colorArray[i] = theVal.toString(16);
}
return colorArray;
}