paper.js/src/color/GradientStop.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2011-03-06 19:50:44 -05:00
/*
* Paper.js
*
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
* based on Scriptographer.org and designed to be largely API compatible.
2011-03-07 20:41:50 -05:00
* http://paperjs.org/
2011-03-06 19:50:44 -05:00
* http://scriptographer.org/
*
2011-03-07 20:41:50 -05:00
* Distributed under the MIT license. See LICENSE file for details.
*
2011-03-06 19:50:44 -05:00
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
2011-03-07 20:41:50 -05:00
* All rights reserved.
2011-03-06 19:50:44 -05:00
*/
// TODO: support midPoint? (initial tests didn't look nice)
var GradientStop = this.GradientStop = Base.extend({
beans: true,
initialize: function(arg0, arg1) {
if (arg1 === undefined && Array.isArray(arg0)) {
// [color, rampPoint]
this.setColor(arg0[0]);
this.setRampPoint(arg0[1]);
} else if (arg0.color) {
// stop
this.setColor(arg0.color);
this.setRampPoint(arg0.rampPoint);
} else {
// color [, rampPoint]
this.setColor(arg0);
this.setRampPoint(arg1);
}
},
clone: function() {
return new GradientStop(this._color.clone(), this._rampPoint);
},
getRampPoint: function() {
return this._rampPoint;
},
setRampPoint: function(rampPoint) {
this._defaultRamp = rampPoint == null;
2011-05-18 04:38:20 -04:00
this._rampPoint = rampPoint || 0;
},
getColor: function() {
return this._color;
},
setColor: function(color) {
this._color = Color.read(arguments);
},
2011-05-18 04:40:03 -04:00
equals: function(stop) {
2011-05-18 04:40:03 -04:00
return stop == this || stop instanceof GradientStop
&& this._color.equals(stop._color)
2011-05-18 05:04:46 -04:00
&& this._rampPoint == stop._rampPoint;
}
2011-03-03 11:32:55 -05:00
});