提交 13582628 编写于 作者: W WestLangley

Remove optionalTarget

上级 f3d71a6e
...@@ -162,10 +162,9 @@ var color = new THREE.Color( 1, 0, 0 ); ...@@ -162,10 +162,9 @@ var color = new THREE.Color( 1, 0, 0 );
<h3>[method:String getHexString]()</h3> <h3>[method:String getHexString]()</h3>
<div>Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').</div> <div>Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').</div>
<h3>[method:Object getHSL]( [param:Object optionalTarget] )</h3> <h3>[method:Object getHSL]( [param:Object target] )</h3>
<div> <div>
[page:Object optionalTarget] — (optional) if specified, adds h, s and l keys to the object (if not already present) [page:Object target] — the result will be copied into this Object. Adds h, s and l keys to the object (if not already present).<br /><br />
and sets the results there. Otherwise, a new Object will be created. <br /><br />
Convert this Color's [page:.r r], [page:.g g] and [page:.b b] values to [link:https://en.wikipedia.org/wiki/HSL_and_HSV HSL] Convert this Color's [page:.r r], [page:.g g] and [page:.b b] values to [link:https://en.wikipedia.org/wiki/HSL_and_HSV HSL]
format and returns an object of the form: format and returns an object of the form:
......
...@@ -17,20 +17,33 @@ THREE.ColorConverter = { ...@@ -17,20 +17,33 @@ THREE.ColorConverter = {
}, },
getHSV: function( color ) { getHSV: function() {
var hsl = color.getHSL(); var hsl = {};
// based on https://gist.github.com/xpansive/1337890#file-index-js return function getHSV( color, target ) {
hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l );
if ( target === undefined ) {
console.warn( 'THREE.ColorConverter: .getHSV() target is now required' );
target = { h: 0, s: 0, l: 0 };
}
color.getHSL( hsl );
// based on https://gist.github.com/xpansive/1337890#file-index-js
hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l );
target.h = hsl.h;
target.s = 2 * hsl.s / ( hsl.l + hsl.s );
target.v = hsl.l + hsl.s;
return target;
return {
h: hsl.h,
s: 2 * hsl.s / ( hsl.l + hsl.s ),
v: hsl.l + hsl.s
}; };
}, }(),
// where c, m, y, k is between 0 and 1 // where c, m, y, k is between 0 and 1
...@@ -44,19 +57,30 @@ THREE.ColorConverter = { ...@@ -44,19 +57,30 @@ THREE.ColorConverter = {
}, },
getCMYK: function ( color ) { getCMYK: function ( color, target ) {
if ( target === undefined ) {
console.warn( 'THREE.ColorConverter: .getCMYK() target is now required' );
target = { c: 0, m: 0, y: 0, k:0 };
}
var r = color.r; var r = color.r;
var g = color.g; var g = color.g;
var b = color.b; var b = color.b;
var k = 1 - Math.max( r, g, b ); var k = 1 - Math.max( r, g, b );
var c = ( 1 - r - k ) / ( 1 - k ); var c = ( 1 - r - k ) / ( 1 - k );
var m = ( 1 - g - k ) / ( 1 - k ); var m = ( 1 - g - k ) / ( 1 - k );
var y = ( 1 - b - k ) / ( 1 - k ); var y = ( 1 - b - k ) / ( 1 - k );
return { target.c = c;
c: c, m: m, y: y, k: k target.m = m;
}; target.y = y;
target.k = k;
return target;
} }
......
...@@ -347,11 +347,16 @@ Object.assign( Color.prototype, { ...@@ -347,11 +347,16 @@ Object.assign( Color.prototype, {
}, },
getHSL: function ( optionalTarget ) { getHSL: function ( target ) {
// h,s,l ranges are in 0.0 - 1.0 // h,s,l ranges are in 0.0 - 1.0
var hsl = optionalTarget || { h: 0, s: 0, l: 0 }; if ( target === undefined ) {
console.warn( 'THREE.Color: .getHSL() target is now required' );
target = { h: 0, s: 0, l: 0 };
}
var r = this.r, g = this.g, b = this.b; var r = this.r, g = this.g, b = this.b;
...@@ -384,11 +389,11 @@ Object.assign( Color.prototype, { ...@@ -384,11 +389,11 @@ Object.assign( Color.prototype, {
} }
hsl.h = hue; target.h = hue;
hsl.s = saturation; target.s = saturation;
hsl.l = lightness; target.l = lightness;
return hsl; return target;
}, },
...@@ -398,17 +403,23 @@ Object.assign( Color.prototype, { ...@@ -398,17 +403,23 @@ Object.assign( Color.prototype, {
}, },
offsetHSL: function ( h, s, l ) { offsetHSL: function () {
var hsl = this.getHSL(); var hsl = {};
hsl.h += h; hsl.s += s; hsl.l += l; return function ( h, s, l ) {
this.setHSL( hsl.h, hsl.s, hsl.l ); this.getHSL( hsl );
return this; hsl.h += h; hsl.s += s; hsl.l += l;
}, this.setHSL( hsl.h, hsl.s, hsl.l );
return this;
};
}(),
add: function ( color ) { add: function ( color ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册