diff options
| author | Jules Laplace <jules@okfoc.us> | 2017-04-29 13:49:36 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2017-04-29 13:49:36 -0400 |
| commit | c27f800fa586b40d2b9baa648cb0c894fdc1e4ef (patch) | |
| tree | 0465838d21beedcac9154d3ecd99fe606e418123 /client/lib/color.js | |
| parent | 91ff874dfe5f7377dc7412dec9a78d03aad45c4d (diff) | |
client init
Diffstat (limited to 'client/lib/color.js')
| -rw-r--r-- | client/lib/color.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/lib/color.js b/client/lib/color.js new file mode 100644 index 0000000..bd5b7ce --- /dev/null +++ b/client/lib/color.js @@ -0,0 +1,31 @@ + +const palettes = [ + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.00, 0.33, 0.67]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.00, 0.10, 0.20]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.30, 0.20, 0.20]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [1.0, 1.0, 0.5], [0.80, 0.90, 0.30]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [1.0, 0.7, 0.4], [0.00, 0.15, 0.20]], + [[0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [2.0, 1.0, 0.0], [0.50, 0.20, 0.25]], + [[0.8, 0.5, 0.4], [0.2, 0.4, 0.2], [2.0, 1.0, 1.0], [0.00, 0.25, 0.25]], +] + +let palette = palettes[0] + +function channel (t, a, b, c, d, add, mul) { + return a + b * Math.cos(2 * Math.PI * (c * t + d)) * mul + add +} + +function color (t, add, mul) { + let a, b, c, d + const rgb = [] + for (var i = 0; i < 3; i++) { + a = palette[0][i] + b = palette[1][i] + c = palette[2][i] + d = palette[3][i] + rgb[i] = Math.round(channel(t, a, b, c, d, add, mul) * 255) + } + return 'rgb(' + rgb + ')' +} + +export default color |
