-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.js
74 lines (59 loc) · 1.92 KB
/
colors.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Generalized interpolation
function getDrawFunction(prop1, prop2, prop3) {
var props = Array.prototype.slice.call(arguments);
var drawFunc = function(canvas, start, end) {
var s = Color(start);
var e = Color(end);
var scales = props.map(function(prop) {
return pv.Scale.linear(0, 1).range(s[prop](), e[prop]());
});
var vis = new pv.Panel()
.canvas(canvas.get(0))
.add(pv.Bar)
.data(pv.range(0, 1, 1/canvas.width()))
.left(function() { return this.index; })
.fillStyle(function(d) {
var c = Color();
_.zip(props, scales).map(function(ps) {
c = c[ps[0]](ps[1](d));
});
return pv.color(c.rgbString());
});
vis.render();
};
return drawFunc;
}
// RGB
function drawRgb(canvas, start, end) {
var f = getDrawFunction('red', 'green', 'blue');
f.apply(this, arguments);
}
// HSL
function drawHsl(canvas, start, end) {
var f = getDrawFunction('hue', 'saturation', 'lightness');
f.apply(this, arguments);
}
// HSV
function drawHsv(canvas, start, end) {
var f = getDrawFunction('hue', 'saturationv', 'value');
f.apply(this, arguments);
}
// CMYK
function drawCmyk(canvas, start, end) {
var f = getDrawFunction('cyan', 'magenta', 'yellow', 'black');
f.apply(this, arguments);
}
// Main doc handler
$(document).ready(function() {
$('button').click(function() {
var form = $(this).siblings('form');
var start = form.children('.start').val();
var end = form.children('.end').val();
drawRgb($('#results div.canvas.rgb'), start, end);
drawHsl($('#results div.canvas.hsl'), start, end);
drawHsv($('#results div.canvas.hsv'), start, end);
drawCmyk($('#results div.canvas.cmyk'), start, end);
return false;
});
$('button').click();
});