A simple test of interpolateHcl from the d3-color module, animated with timer from the d3-transition module. Note that interpolateHcl chooses the shortest path between two hues, and the change in hue is thus always less than 180°; use interpolateHclLong to take the long path.
xxxxxxxxxx
<meta charset="utf-8">
<canvas width="960" height="1" style="width:960px;height:500px;"></canvas>
<script src="d3.min.js"></script>
<script>
var canvas = document.querySelector("canvas"),
width = canvas.width,
context = canvas.getContext("2d"),
image = context.createImageData(width, 1);
d3.timer(function(elapsed) {
var hue = elapsed * .1,
interpolate = d3.interpolateHcl(d3.hcl(hue, 50, 95), d3.hcl(hue + 120, 50, 25));
for (var i = 0, j = -1, c; i < width; ++i) {
c = d3.rgb(interpolate(i / (width - 1)));
image.data[++j] = c.r;
image.data[++j] = c.g;
image.data[++j] = c.b;
image.data[++j] = 255;
}
context.putImageData(image, 0, 0);
});
</script>