Skip to content

Commit

Permalink
add CIELab interpolator
Browse files Browse the repository at this point in the history
  • Loading branch information
justincormack committed Mar 4, 2012
1 parent f1b3831 commit a00c344
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
24 changes: 14 additions & 10 deletions d3.v2.js
Expand Up @@ -1082,6 +1082,20 @@ d3.interpolateHsl = function(a, b) {
};
};

d3.interpolateLab = function(a, b) {
a = d3.lab(a);
b = d3.lab(b);
var l0 = a.l,
a0 = a.a,
b0 = a.b,
l1 = b.l - l0,
a1 = b.a - a0,
b1 = b.b - b0;
return function(t) {
return d3_lab_rgb(l0 + l1 * t, a0 + a1 * t, b0 + b1 * t).toString();
};
};

d3.interpolateArray = function(a, b) {
var x = [],
c = [],
Expand Down Expand Up @@ -1619,16 +1633,6 @@ function d3_lab_rgb(l, a, b) {
return d3_rgb(w(r), w(g), w(b));
}

function d3_lab_cielch(l, a, b) {
var h = Math.atan2(b, a);

h = h > 0 ? (h / Math.PI) * 180 : 360 - (Math.abs(h) / Math.PI) * 180;

c = Math.sqrt(a * a + b * b);

return d3_cielch(l, c, h);
}

function d3_lab_lch(l, c, h) {
var hr = h * (Math.PI / 180);
var a = Math.cos(hr) * c;
Expand Down

0 comments on commit a00c344

Please sign in to comment.