I've got a gradient like so:
var graphic = new createjs.Graphics().beginLinearGradientFill(
["#000", "#fff", "#000"],
[0, 0.5, 1],
0, 0,
window.innerWidth, window.innerHeight
).drawRect(0, 0, window.innerWidth, window.innerHeight);
var shape = new createjs.Shape(graphic);
How would I animate the gradient so that it appears to be moving? (i.e. if this were CSS-made, the background-position would slowly change)
Unfortunately Canvas gradients are not as simple to animate as CSS. You have to rebuild the gradient command any time it changes.
I built a quick demo that can facilitate this, though it requires the most recent NEXT version of TweenJS, which has a great ColorPlugin for animating the color stops.
http://jsfiddle.net/lannymcnie/uhqake7e/ UPDATE: Easier approach http://jsfiddle.net/uhqake7e/2/
The key pieces:
For more on commands, check out this article.
Then we can tween the color values:
And lastly, rebuild the gradient on change: [UPDATED: Simpler approach]
A similar approach would be to use the color tween, and just redraw the shape's contents, but it would require you to store ALL the instructions. This sample updates the actual command used for the Gradient.
It is too bad this has to somewhat convoluted, especially since CSS is so simple :)
Cheers.