1 /**
2 * @author mrdoob / http://mrdoob.com/
3 */
4
5 /**@constructor*/
6 THREE.Color = function ( hex ) {
7
8 if ( hex !== undefined ) this.setHex( hex );
9
10 return this;
11
12 };
13
14 THREE.Color.prototype = {
15
16 constructor: THREE.Color,
17
18 r: 1, g: 1, b: 1,
19
20 copy: function ( color ) {
21
22 this.r = color.r;
23 this.g = color.g;
24 this.b = color.b;
25
26 return this;
27
28 },
29
30 copyGammaToLinear: function ( color ) {
31
32 this.r = color.r * color.r;
33 this.g = color.g * color.g;
34 this.b = color.b * color.b;
35
36 return this;
37
38 },
39
40 copyLinearToGamma: function ( color ) {
41
42 this.r = Math.sqrt( color.r );
43 this.g = Math.sqrt( color.g );
44 this.b = Math.sqrt( color.b );
45
46 return this;
47
48 },
49
50 convertGammaToLinear: function () {
51
52 var r = this.r, g = this.g, b = this.b;
53
54 this.r = r * r;
55 this.g = g * g;
56 this.b = b * b;
57
58 return this;
59
60 },
61
62 convertLinearToGamma: function () {
63
64 this.r = Math.sqrt( this.r );
65 this.g = Math.sqrt( this.g );
66 this.b = Math.sqrt( this.b );
67
68 return this;
69
70 },
71
72 setRGB: function ( r, g, b ) {
73
74 this.r = r;
75 this.g = g;
76 this.b = b;
77
78 return this;
79
80 },
81
82 setHSV: function ( h, s, v ) {
83
84 // based on MochiKit implementation by Bob Ippolito
85 // h,s,v ranges are < 0.0 - 1.0 >
86
87 var i, f, p, q, t;
88
89 if ( v === 0 ) {
90
91 this.r = this.g = this.b = 0;
92
93 } else {
94
95 i = Math.floor( h * 6 );
96 f = ( h * 6 ) - i;
97 p = v * ( 1 - s );
98 q = v * ( 1 - ( s * f ) );
99 t = v * ( 1 - ( s * ( 1 - f ) ) );
100
101 if ( i === 0 ) {
102
103 this.r = v;
104 this.g = t;
105 this.b = p;
106
107 } else if ( i === 1 ) {
108
109 this.r = q;
110 this.g = v;
111 this.b = p;
112
113 } else if ( i === 2 ) {
114
115 this.r = p;
116 this.g = v;
117 this.b = t;
118
119 } else if ( i === 3 ) {
120
121 this.r = p;
122 this.g = q;
123 this.b = v;
124
125 } else if ( i === 4 ) {
126
127 this.r = t;
128 this.g = p;
129 this.b = v;
130
131 } else if ( i === 5 ) {
132
133 this.r = v;
134 this.g = p;
135 this.b = q;
136
137 }
138
139 }
140
141 return this;
142
143 },
144
145 getHex: function () {
146
147 return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
148
149 },
150
151 setHex: function ( hex ) {
152
153 hex = Math.floor( hex );
154
155 this.r = ( hex >> 16 & 255 ) / 255;
156 this.g = ( hex >> 8 & 255 ) / 255;
157 this.b = ( hex & 255 ) / 255;
158
159 return this;
160
161 },
162
163 getHexString: function () {
164
165 return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
166
167 },
168
169 getContextStyle: function () {
170
171 return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
172
173 },
174
175 setContextStyle: function ( style ) {
176
177 var color = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/i.exec( style );
178
179 this.r = parseInt( color[ 1 ], 10 ) / 255;
180 this.g = parseInt( color[ 2 ], 10 ) / 255;
181 this.b = parseInt( color[ 3 ], 10 ) / 255;
182
183 return this;
184
185 },
186
187 getHSV: function ( hsv ) {
188
189 // based on MochiKit implementation by Bob Ippolito
190 // h,s,v ranges are < 0.0 - 1.0 >
191
192 var r = this.r;
193 var g = this.g;
194 var b = this.b;
195
196 var max = Math.max( Math.max( r, g ), b );
197 var min = Math.min( Math.min( r, g ), b );
198
199 var hue;
200 var saturation;
201 var value = max;
202
203 if ( min === max ) {
204
205 hue = 0;
206 saturation = 0;
207
208 } else {
209
210 var delta = ( max - min );
211 saturation = delta / max;
212
213 if ( r === max ) {
214
215 hue = ( g - b ) / delta;
216
217 } else if ( g === max ) {
218
219 hue = 2 + ( ( b - r ) / delta );
220
221 } else {
222
223 hue = 4 + ( ( r - g ) / delta );
224 }
225
226 hue /= 6;
227
228 if ( hue < 0 ) {
229
230 hue += 1;
231
232 }
233
234 if ( hue > 1 ) {
235
236 hue -= 1;
237
238 }
239
240 }
241
242 if ( hsv === undefined ) {
243
244 hsv = { h: 0, s: 0, v: 0 };
245
246 }
247
248 hsv.h = hue;
249 hsv.s = saturation;
250 hsv.v = value;
251
252 return hsv;
253
254 },
255
256 lerpSelf: function ( color, alpha ) {
257
258 this.r += ( color.r - this.r ) * alpha;
259 this.g += ( color.g - this.g ) * alpha;
260 this.b += ( color.b - this.b ) * alpha;
261
262 return this;
263
264 },
265
266 clone: function () {
267
268 return new THREE.Color().setRGB( this.r, this.g, this.b );
269
270 }
271
272 };
273
nike free rn
new balance hombre baratas
cinturones gucci
ugg rebajas
cinturon gucci
ray ban baratas
nike cortez
peuterey mujer
christian louboutin madrid
mbt zapatos
gafas ray ban baratas
mbt ofertas
air max blancas
mbt barcelona
nike air max 90
woolrich barcelona
nike mujer
botas ugg
gafas de sol carrera aratas
air max 2016 baratas
oakley baratas
nike air max 2016