paper.js/src/color/HSBColor.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

/*
* 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.
* http://paperjs.org/
* http://scriptographer.org/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* All rights reserved.
*/
var HSBColor = this.HSBColor = Color.extend(new function() {
var components = ['hue', 'saturation', 'brightness', 'alpha'];
return Base.each(components, function(name) {
var internalName = '_' + name;
name = Base.capitalize(name);
if (name !== 'alpha') {
this['get' + name] = function() {
return this[internalName];
};
// Avoid overriding setHue:
if (!this['set' + name]) {
this['set' + name] = function(value) {
this._cssString = null;
this[internalName] = Math.min(Math.max(value, 0), 1);
return this;
};
}
}
2011-03-09 08:31:40 -05:00
}, {
beans: true,
_colorType: 'hsb',
_components: components,
setHue: function(hue) {
if (hue < 0)
hue = 360 + hue;
this._cssString = null;
2011-03-08 20:30:50 -05:00
this._hue = hue % 360;
return this;
}
});
2011-03-09 08:31:40 -05:00
});