mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
No need to clamp colors in conversions, just make sure hue stays within 360°
This commit is contained in:
parent
22e62a0527
commit
6ed264a775
1 changed files with 7 additions and 23 deletions
|
@ -132,8 +132,9 @@ var Color = Base.extend(new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
'hsb-rgb': function(h, s, b) {
|
'hsb-rgb': function(h, s, b) {
|
||||||
var h = (h / 60) % 6, // Scale to 0..6
|
// Scale h to 0..6 with modulo for negative values too
|
||||||
i = Math.floor(h), // 0..5
|
h = (((h / 60) % 6) + 6) % 6;
|
||||||
|
var i = Math.floor(h), // 0..5
|
||||||
f = h - i,
|
f = h - i,
|
||||||
i = hsbIndices[i],
|
i = hsbIndices[i],
|
||||||
v = [
|
v = [
|
||||||
|
@ -164,7 +165,8 @@ var Color = Base.extend(new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
'hsl-rgb': function(h, s, l) {
|
'hsl-rgb': function(h, s, l) {
|
||||||
h /= 360;
|
// Scale h to 0..1 with modulo for negative values too
|
||||||
|
h = (((h / 360) % 1) + 1) % 1;
|
||||||
if (s === 0)
|
if (s === 0)
|
||||||
return [l, l, l];
|
return [l, l, l];
|
||||||
var t3s = [ h + 1 / 3, h, h - 1 / 3 ],
|
var t3s = [ h + 1 / 3, h, h - 1 / 3 ],
|
||||||
|
@ -647,24 +649,6 @@ var Color = Base.extend(new function() {
|
||||||
this._owner._changed(/*#=*/ Change.STYLE);
|
this._owner._changed(/*#=*/ Change.STYLE);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of the components array with all values clamped to
|
|
||||||
* valid numbers, based on the type of property they represent.
|
|
||||||
*/
|
|
||||||
_clamp: function() {
|
|
||||||
var components = this._components.slice(),
|
|
||||||
properties = this._properties;
|
|
||||||
if (this._type !== 'gradient') {
|
|
||||||
for (var i = 0, l = properties.length; i < l; i++) {
|
|
||||||
var value = components[i];
|
|
||||||
components[i] = properties[i] === 'hue'
|
|
||||||
? ((value % 360) + 360) % 360
|
|
||||||
: value < 0 ? 0 : value > 1 ? 1 : value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return components;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {Number[]} the converted components as an array
|
* @return {Number[]} the converted components as an array
|
||||||
*/
|
*/
|
||||||
|
@ -673,11 +657,11 @@ var Color = Base.extend(new function() {
|
||||||
return this._type === type
|
return this._type === type
|
||||||
? this._components.slice()
|
? this._components.slice()
|
||||||
: (converter = converters[this._type + '-' + type])
|
: (converter = converters[this._type + '-' + type])
|
||||||
? converter.apply(this, this._clamp())
|
? converter.apply(this, this._components)
|
||||||
// Convert to and from rgb if no direct converter exists
|
// Convert to and from rgb if no direct converter exists
|
||||||
: converters['rgb-' + type].apply(this,
|
: converters['rgb-' + type].apply(this,
|
||||||
converters[this._type + '-rgb'].apply(this,
|
converters[this._type + '-rgb'].apply(this,
|
||||||
this._clamp()));
|
this._components));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue