diff --git a/src/color/Gradient.js b/src/color/Gradient.js index feb699fc..2ab4e922 100644 --- a/src/color/Gradient.js +++ b/src/color/Gradient.js @@ -17,11 +17,15 @@ var Gradient = this.Gradient = Base.extend({ beans: true, - initialize: function() { - this.setStops([ - new GradientStop('white', 0), - new GradientStop('black', 1)]); - this.type = 'linear'; + // Todo: should type here be called 'radial' and have it + // receive a boolean value? + initialize: function(stops, type) { + if(!stops) { + stops = [new GradientStop('white', 0), + new GradientStop('black', 1)]; + } + this.setStops(stops); + this.type = type ? type : 'linear'; }, getStops: function() { @@ -32,6 +36,22 @@ var Gradient = this.Gradient = Base.extend({ if (stops.length < 2) throw new Error( 'Gradient stop list needs to contain at least two stops.'); + if(!(stops[0] instanceof GradientStop)) { + for(var i = 0, l = stops.length; i < l; i++) { + var midPoint; + var stop = stops[i]; + // If it is an array, the second argument is the midPoint: + if(stop.length) { + midPoint = stop[1]; + stop = stop[0]; + } else { + // Otherwise stops is an array of colors, and we need to + // calculate the midPoint: + midPoint = i / (l - 1); + } + stops[i] = new GradientStop(stop, midPoint); + } + } this._stops = stops; } });