forked from rupl/j5-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_utils.js
37 lines (34 loc) · 854 Bytes
/
_utils.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
31
32
33
34
35
36
37
//
// Color wheel
//
// Input any number to get a color value. The number is the absolute value of
// modulus of 255, and the colors continuously transition in a seamless cycle:
//
// r ⇢ g ⇢ b ⇢ r
//
exports.colorwheel = function(WheelPos) {
var r,g,b;
WheelPos = (0 > WheelPos) ? -WheelPos : WheelPos;
WheelPos = 255 - (WheelPos % 255);
if ( WheelPos < 85 ) {
r = 255 - WheelPos * 3;
g = 0;
b = WheelPos * 3;
} else if (WheelPos < 170) {
WheelPos -= 85;
r = 0;
g = WheelPos * 3;
b = 255 - WheelPos * 3;
} else {
WheelPos -= 170;
r = WheelPos * 3;
g = 255 - WheelPos * 3;
b = 0;
}
// tone it down
r = Math.floor(r/2);
g = Math.floor(g/2);
b = Math.floor(b/2);
// returns a string with the rgb value to be used as the parameter
return "rgb(" + r +"," + g + "," + b + ")";
};