| 846 | ]; |
| 847 | |
| 848 | function _rotateRYB(h, s, b, angle) { |
| 849 | /* Rotates the given H,S,B color (0.0-1.0) on the RYB color wheel. |
| 850 | * The RYB colorwheel is not mathematically precise, |
| 851 | * but focuses on aesthetically pleasing complementary colors. |
| 852 | */ |
| 853 | if (angle === undefined) angle = 180; |
| 854 | h = h * 360 % 360; |
| 855 | // Find the location (angle) of the hue on the RYB color wheel. |
| 856 | var x0, y0, x1, y1, a; |
| 857 | var wheel = _COLORWHEEL; |
| 858 | for (var i=0; i < wheel.length-1; i++) { |
| 859 | x0 = wheel[i][0]; x1 = wheel[i+1][0]; |
| 860 | y0 = wheel[i][1]; y1 = wheel[i+1][1]; |
| 861 | if (y0 <= h && h <= y1) { |
| 862 | a = geometry.lerp(x0, x1, (h-y0) / (y1-y0)); |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | // Rotate the angle and retrieve the hue. |
| 867 | a = (a+angle) % 360; |
| 868 | for (var i=0; i < wheel.length-1; i++) { |
| 869 | x0 = wheel[i][0]; x1 = wheel[i+1][0]; |
| 870 | y0 = wheel[i][1]; y1 = wheel[i+1][1]; |
| 871 | if (x0 <= a && a <= x1) { |
| 872 | h = geometry.lerp(y0, y1, (a-x0) / (x1-x0)); |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | return [h/360.0, s, b]; |
| 877 | } |
| 878 | |
| 879 | function complement(clr) { |
| 880 | /* Returns the color opposite on the color wheel. |