mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Compress HSL and HSB converters even more.
This commit is contained in:
parent
adff506751
commit
baf7136ef7
1 changed files with 9 additions and 25 deletions
|
@ -114,19 +114,12 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
max = Math.max(r, g, b),
|
max = Math.max(r, g, b),
|
||||||
min = Math.min(r, g, b),
|
min = Math.min(r, g, b),
|
||||||
delta = max - min,
|
delta = max - min,
|
||||||
h,
|
h = delta == 0 ? 0
|
||||||
|
: ( max == r ? (g - b) / delta + (g < b ? 6 : 0)
|
||||||
|
: max == g ? (b - r) / delta + 2
|
||||||
|
: (r - g) / delta + 4) * 60, // max == b
|
||||||
s = max == 0 ? 0 : delta / max,
|
s = max == 0 ? 0 : delta / max,
|
||||||
v = max; // = brightness, also called value
|
v = max; // = brightness, also called value
|
||||||
if (delta == 0) {
|
|
||||||
h = 0; // Achromatic
|
|
||||||
} else {
|
|
||||||
switch (max) {
|
|
||||||
case r: h = (g - b) / delta + (g < b ? 6 : 0); break;
|
|
||||||
case g: h = (b - r) / delta + 2; break;
|
|
||||||
case b: h = (r - g) / delta + 4; break;
|
|
||||||
}
|
|
||||||
h *= 60;
|
|
||||||
}
|
|
||||||
return new HSBColor(h, s, v, color._alpha);
|
return new HSBColor(h, s, v, color._alpha);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -155,23 +148,14 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
max = Math.max(r, g, b),
|
max = Math.max(r, g, b),
|
||||||
min = Math.min(r, g, b),
|
min = Math.min(r, g, b),
|
||||||
delta = max - min,
|
delta = max - min,
|
||||||
h,
|
h = delta == 0 ? 0
|
||||||
s,
|
: ( max == r ? (g - b) / delta + (g < b ? 6 : 0)
|
||||||
l = (max + min) / 2;
|
: max == g ? (b - r) / delta + 2
|
||||||
if (delta == 0) {
|
: (r - g) / delta + 4) * 60, // max == b
|
||||||
h = s = 0;
|
l = (max + min) / 2,
|
||||||
} else {
|
|
||||||
s = l < 0.5
|
s = l < 0.5
|
||||||
? delta / (max + min)
|
? delta / (max + min)
|
||||||
: delta / (2 - max - min);
|
: delta / (2 - max - min);
|
||||||
}
|
|
||||||
switch (max) {
|
|
||||||
case r: h = (g - b) / delta; break;
|
|
||||||
case g: h = (b - r) / delta + 2; break;
|
|
||||||
case b: h = (r - g) / delta + 4; break;
|
|
||||||
}
|
|
||||||
h *= 60;
|
|
||||||
if (h < 0) h += 360;
|
|
||||||
return new HSLColor(h, s, l, color._alpha);
|
return new HSLColor(h, s, l, color._alpha);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue