UNPKG

@sky-foundry/two.js

Version:

A renderer agnostic two-dimensional drawing api for the web.

129 lines (81 loc) 2.56 kB
(function(Two) { var _ = Two.Utils; var RadialGradient = Two.RadialGradient = function(cx, cy, r, stops, fx, fy) { Two.Gradient.call(this, stops); this._renderer.type = 'radial-gradient'; this.center = new Two.Vector() .bind(Two.Events.change, _.bind(function() { this._flagCenter = true; }, this)); this.radius = _.isNumber(r) ? r : 20; this.focal = new Two.Vector() .bind(Two.Events.change, _.bind(function() { this._flagFocal = true; }, this)); if (_.isNumber(cx)) { this.center.x = cx; } if (_.isNumber(cy)) { this.center.y = cy; } this.focal.copy(this.center); if (_.isNumber(fx)) { this.focal.x = fx; } if (_.isNumber(fy)) { this.focal.y = fy; } }; _.extend(RadialGradient, { Stop: Two.Gradient.Stop, Properties: [ 'radius' ], MakeObservable: function(object) { Two.Gradient.MakeObservable(object); _.each(RadialGradient.Properties, Two.Utils.defineProperty, object); } }); _.extend(RadialGradient.prototype, Two.Gradient.prototype, { _flagRadius: false, _flagCenter: false, _flagFocal: false, constructor: RadialGradient, clone: function(parent) { var stops = _.map(this.stops, function(stop) { return stop.clone(); }); var clone = new RadialGradient(this.center._x, this.center._y, this._radius, stops, this.focal._x, this.focal._y); _.each(Two.Gradient.Properties.concat(RadialGradient.Properties), function(k) { clone[k] = this[k]; }, this); if (parent) { parent.add(clone); } return clone; }, toObject: function() { var result = Two.Gradient.prototype.toObject.call(this); _.each(RadialGradient.Properties, function(k) { result[k] = this[k]; }, this); result.center = this.center.toObject(); result.focal = this.focal.toObject(); return result; }, _update: function() { if (this._flagRadius || this._flatCenter || this._flagFocal || this._flagSpread || this._flagStops) { this.trigger(Two.Events.change); } return this; }, flagReset: function() { this._flagRadius = this._flagCenter = this._flagFocal = false; Two.Gradient.prototype.flagReset.call(this); return this; } }); RadialGradient.MakeObservable(RadialGradient.prototype); })((typeof global !== 'undefined' ? global : (this || window)).Two);