Improve GradientStop example code.

This commit is contained in:
Jonathan Puckey 2013-04-21 15:35:45 +02:00
parent fbc3985bbf
commit 191213f362

View file

@ -87,14 +87,16 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
* radius: view.bounds.height * 0.4 * radius: view.bounds.height * 0.4
* }); * });
* *
* // Prepare the gradient color and apply it to the path: * path.fillColor = {
* var colors = [['yellow', 0.05], ['red', 0.2], ['black', 1]]; * gradient: {
* var gradient = new Gradient(colors, true); * stops: [['yellow', 0.05], ['red', 0.2], ['black', 1]],
* var from = path.position; * radial: true
* var to = path.bounds.rightCenter; * },
* var gradientColor = new Color(gradient, from, to); * origin: path.position,
* destination: path.bounds.rightCenter
* };
* *
* path.fillColor = gradientColor; * var gradient = path.fillColor.gradient;
* *
* // This function is called each frame of the animation: * // This function is called each frame of the animation:
* function onFrame(event) { * function onFrame(event) {
@ -133,21 +135,26 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
* center: view.center, * center: view.center,
* radius: view.bounds.height * 0.4 * radius: view.bounds.height * 0.4
* }); * });
* *
* // Create a radial gradient that mixes red and black evenly: * path.fillColor = {
* var gradient = new Gradient(['red', 'black'], true); * gradient: {
* * stops: [['yellow', 0.05], ['red', 0.2], ['black', 1]],
* // Fill the path with a gradient color that runs from its center, * radial: true
* // to the right center of its bounding rectangle: * },
* var from = path.position; * origin: path.position,
* var to = path.bounds.rightCenter; * destination: path.bounds.rightCenter
* var gradientColor = new Color(gradient, from, to); * };
* path.fillColor = gradientColor; *
* * var redStop = path.fillColor.gradient.stops[1];
* var blackStop = path.fillColor.gradient.stops[2];
*
* // This function is called each frame of the animation: * // This function is called each frame of the animation:
* function onFrame(event) { * function onFrame(event) {
* // Change the hue of the first stop's color: * // Animate the rampPoint between 0.7 and 0.9:
* gradient.stops[0].color.hue += 1; * blackStop.rampPoint = Math.sin(event.time * 5) * 0.1 + 0.8;
*
* // Animate the rampPoint between 0.2 and 0.4
* redStop.rampPoint = Math.sin(event.time * 3) * 0.1 + 0.3;
* } * }
*/ */
getColor: function() { getColor: function() {