Search code examples
javascriptpaperjs

Animating colors in paper.js


Is there a color delta object in paper.js, which can store negative values in each component? What I'm trying to achieve here is to animate a color to another color smoothly, by storing the color change in each frame in this color delta object.

Simply subtracting one color from another does not work, as negative values are not permitted:

var color1 = new Color(0, 1, 1);
var color2 = new Color(1, 0, 0);
var result = color1 - color2;
console.log(result); // { red: 0, blue: 1, green: 1 }

Any suggestions, including easier ways to achieve the same animation effect would be appreciated.


Solution

  • Yes it's a known issue that negative components are not allowed. I'm thinking of changing this and moving the clamping of values further down:

    https://github.com/paperjs/paper.js/issues/271