Color.html 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Color - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">Color</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>A Color instance is represented by RGB components in the linear <i>working
  16. color space</i>, which defaults to <code>LinearSRGBColorSpace</code>. Inputs
  17. conventionally using <code>SRGBColorSpace</code> (such as hexadecimals and CSS
  18. strings) are converted to the working color space automatically.</p>
  19. <p>Source color spaces may be specified explicitly, to ensure correct conversions.</p>
  20. <pre><code class="language-js">// assumed already LinearSRGBColorSpace; no conversion
  21. const color = new THREE.Color().setRGB( 0.5, 0.5, 0.5 );
  22. // converted explicitly from SRGBColorSpace to LinearSRGBColorSpace
  23. const color = new THREE.Color().setRGB( 0.5, 0.5, 0.5, SRGBColorSpace );
  24. </code></pre>
  25. <p>If THREE.ColorManagement is disabled, no conversions occur. For details,
  26. see <i>Color management</i>. Iterating through a Color instance will yield
  27. its components (r, g, b) in the corresponding order. A Color can be initialised
  28. in any of the following ways:</p>
  29. <pre><code class="language-js">//empty constructor - will default white
  30. const color1 = new THREE.Color();
  31. //Hexadecimal color (recommended)
  32. const color2 = new THREE.Color( 0xff0000 );
  33. //RGB string
  34. const color3 = new THREE.Color(&quot;rgb(255, 0, 0)&quot;);
  35. const color4 = new THREE.Color(&quot;rgb(100%, 0%, 0%)&quot;);
  36. //X11 color name - all 140 color names are supported.
  37. //Note the lack of CamelCase in the name
  38. const color5 = new THREE.Color( 'skyblue' );
  39. //HSL string
  40. const color6 = new THREE.Color(&quot;hsl(0, 100%, 50%)&quot;);
  41. //Separate RGB values between 0 and 1
  42. const color7 = new THREE.Color( 1, 0, 0 );
  43. </code></pre></div>
  44. <h2>Code Example</h2>
  45. <div translate="no"><pre><code class="language-js">// converted automatically from SRGBColorSpace to LinearSRGBColorSpace
  46. const color = new THREE.Color().setHex( 0x112233 );
  47. </code></pre></div>
  48. </header>
  49. <article>
  50. <div class="container-overview">
  51. <h2>Constructor</h2>
  52. <h3 class="name name-method" id="Color" translate="no">new <a href="#Color">Color</a><span class="signature">( r : <span class="param-type">number | string | <a href="Color.html">Color</a></span>, g : <span class="param-type">number</span>, b : <span class="param-type">number</span> )</span> </h3>
  53. <div class="method">
  54. <div class="description">
  55. <p>Constructs a new color.</p>
  56. <p>Note that standard method of specifying color in three.js is with a hexadecimal triplet,
  57. and that method is used throughout the rest of the documentation.</p>
  58. </div>
  59. <table class="params">
  60. <tbody>
  61. <tr>
  62. <td class="name">
  63. <strong>r</strong>
  64. </td>
  65. <td class="description last">
  66. <p>The red component of the color. If <code>g</code> and <code>b</code> are
  67. not provided, it can be hexadecimal triplet, a CSS-style string or another <code>Color</code> instance.</p>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td class="name">
  72. <strong>g</strong>
  73. </td>
  74. <td class="description last">
  75. <p>The green component.</p>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td class="name">
  80. <strong>b</strong>
  81. </td>
  82. <td class="description last">
  83. <p>The blue component.</p>
  84. </td>
  85. </tr>
  86. </tbody>
  87. </table>
  88. </div>
  89. </div>
  90. <h2 class="subsection-title">Properties</h2>
  91. <div class="member">
  92. <h3 class="name" id="b" translate="no">.<a href="#b">b</a><span class="type-signature"> : number</span> </h3>
  93. <div class="description">
  94. <p>The blue component.</p>
  95. <p>Default is <code>1</code>.</p>
  96. </div>
  97. </div>
  98. <div class="member">
  99. <h3 class="name" id="g" translate="no">.<a href="#g">g</a><span class="type-signature"> : number</span> </h3>
  100. <div class="description">
  101. <p>The green component.</p>
  102. <p>Default is <code>1</code>.</p>
  103. </div>
  104. </div>
  105. <div class="member">
  106. <h3 class="name" id="isColor" translate="no">.<a href="#isColor">isColor</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  107. <div class="description">
  108. <p>This flag can be used for type testing.</p>
  109. <p>Default is <code>true</code>.</p>
  110. </div>
  111. </div>
  112. <div class="member">
  113. <h3 class="name" id="r" translate="no">.<a href="#r">r</a><span class="type-signature"> : number</span> </h3>
  114. <div class="description">
  115. <p>The red component.</p>
  116. <p>Default is <code>1</code>.</p>
  117. </div>
  118. </div>
  119. <div class="member">
  120. <h3 class="name" id=".NAMES" translate="no">.<a href="#.NAMES">NAMES</a><span class="type-signature"> : Object</span> </h3>
  121. <div class="description">
  122. <p>A dictionary with X11 color names.</p>
  123. <p>Note that multiple words such as Dark Orange become the string 'darkorange'.</p>
  124. </div>
  125. </div>
  126. <h2 class="subsection-title">Methods</h2>
  127. <h3 class="name name-method" id="add" translate="no">.<a href="#add">add</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  128. <div class="method">
  129. <div class="description">
  130. <p>Adds the RGB values of the given color to the RGB values of this color.</p>
  131. </div>
  132. <table class="params">
  133. <tbody>
  134. <tr>
  135. <td class="name">
  136. <strong>color</strong>
  137. </td>
  138. <td class="description last">
  139. <p>The color to add.</p>
  140. </td>
  141. </tr>
  142. </tbody>
  143. </table>
  144. <dl class="details">
  145. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  146. </dl>
  147. </div>
  148. <h3 class="name name-method" id="addColors" translate="no">.<a href="#addColors">addColors</a><span class="signature">( color1 : <span class="param-type"><a href="Color.html">Color</a></span>, color2 : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  149. <div class="method">
  150. <div class="description">
  151. <p>Adds the RGB values of the given colors and stores the result in this instance.</p>
  152. </div>
  153. <table class="params">
  154. <tbody>
  155. <tr>
  156. <td class="name">
  157. <strong>color1</strong>
  158. </td>
  159. <td class="description last">
  160. <p>The first color.</p>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td class="name">
  165. <strong>color2</strong>
  166. </td>
  167. <td class="description last">
  168. <p>The second color.</p>
  169. </td>
  170. </tr>
  171. </tbody>
  172. </table>
  173. <dl class="details">
  174. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  175. </dl>
  176. </div>
  177. <h3 class="name name-method" id="addScalar" translate="no">.<a href="#addScalar">addScalar</a><span class="signature">( s : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  178. <div class="method">
  179. <div class="description">
  180. <p>Adds the given scalar value to the RGB values of this color.</p>
  181. </div>
  182. <table class="params">
  183. <tbody>
  184. <tr>
  185. <td class="name">
  186. <strong>s</strong>
  187. </td>
  188. <td class="description last">
  189. <p>The scalar to add.</p>
  190. </td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. <dl class="details">
  195. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  196. </dl>
  197. </div>
  198. <h3 class="name name-method" id="applyMatrix3" translate="no">.<a href="#applyMatrix3">applyMatrix3</a><span class="signature">( m : <span class="param-type"><a href="Matrix3.html">Matrix3</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  199. <div class="method">
  200. <div class="description">
  201. <p>Transforms this color with the given 3x3 matrix.</p>
  202. </div>
  203. <table class="params">
  204. <tbody>
  205. <tr>
  206. <td class="name">
  207. <strong>m</strong>
  208. </td>
  209. <td class="description last">
  210. <p>The matrix.</p>
  211. </td>
  212. </tr>
  213. </tbody>
  214. </table>
  215. <dl class="details">
  216. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  217. </dl>
  218. </div>
  219. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  220. <div class="method">
  221. <div class="description">
  222. <p>Returns a new color with copied values from this instance.</p>
  223. </div>
  224. <dl class="details">
  225. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  226. </dl>
  227. </div>
  228. <h3 class="name name-method" id="convertLinearToSRGB" translate="no">.<a href="#convertLinearToSRGB">convertLinearToSRGB</a><span class="signature">()</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  229. <div class="method">
  230. <div class="description">
  231. <p>Converts this color from <code>LinearSRGBColorSpace</code> to <code>SRGBColorSpace</code>.</p>
  232. </div>
  233. <dl class="details">
  234. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  235. </dl>
  236. </div>
  237. <h3 class="name name-method" id="convertSRGBToLinear" translate="no">.<a href="#convertSRGBToLinear">convertSRGBToLinear</a><span class="signature">()</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  238. <div class="method">
  239. <div class="description">
  240. <p>Converts this color from <code>SRGBColorSpace</code> to <code>LinearSRGBColorSpace</code>.</p>
  241. </div>
  242. <dl class="details">
  243. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  244. </dl>
  245. </div>
  246. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  247. <div class="method">
  248. <div class="description">
  249. <p>Copies the values of the given color to this instance.</p>
  250. </div>
  251. <table class="params">
  252. <tbody>
  253. <tr>
  254. <td class="name">
  255. <strong>color</strong>
  256. </td>
  257. <td class="description last">
  258. <p>The color to copy.</p>
  259. </td>
  260. </tr>
  261. </tbody>
  262. </table>
  263. <dl class="details">
  264. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  265. </dl>
  266. </div>
  267. <h3 class="name name-method" id="copyLinearToSRGB" translate="no">.<a href="#copyLinearToSRGB">copyLinearToSRGB</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  268. <div class="method">
  269. <div class="description">
  270. <p>Copies the given color into this color, and then converts this color from
  271. <code>LinearSRGBColorSpace</code> to <code>SRGBColorSpace</code>.</p>
  272. </div>
  273. <table class="params">
  274. <tbody>
  275. <tr>
  276. <td class="name">
  277. <strong>color</strong>
  278. </td>
  279. <td class="description last">
  280. <p>The color to copy/convert.</p>
  281. </td>
  282. </tr>
  283. </tbody>
  284. </table>
  285. <dl class="details">
  286. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  287. </dl>
  288. </div>
  289. <h3 class="name name-method" id="copySRGBToLinear" translate="no">.<a href="#copySRGBToLinear">copySRGBToLinear</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  290. <div class="method">
  291. <div class="description">
  292. <p>Copies the given color into this color, and then converts this color from
  293. <code>SRGBColorSpace</code> to <code>LinearSRGBColorSpace</code>.</p>
  294. </div>
  295. <table class="params">
  296. <tbody>
  297. <tr>
  298. <td class="name">
  299. <strong>color</strong>
  300. </td>
  301. <td class="description last">
  302. <p>The color to copy/convert.</p>
  303. </td>
  304. </tr>
  305. </tbody>
  306. </table>
  307. <dl class="details">
  308. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  309. </dl>
  310. </div>
  311. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( c : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  312. <div class="method">
  313. <div class="description">
  314. <p>Returns <code>true</code> if this color is equal with the given one.</p>
  315. </div>
  316. <table class="params">
  317. <tbody>
  318. <tr>
  319. <td class="name">
  320. <strong>c</strong>
  321. </td>
  322. <td class="description last">
  323. <p>The color to test for equality.</p>
  324. </td>
  325. </tr>
  326. </tbody>
  327. </table>
  328. <dl class="details">
  329. <dt class="tag-returns"><strong>Returns:</strong> Whether this bounding color is equal with the given one.</dt>
  330. </dl>
  331. </div>
  332. <h3 class="name name-method" id="fromArray" translate="no">.<a href="#fromArray">fromArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  333. <div class="method">
  334. <div class="description">
  335. <p>Sets this color's RGB components from the given array.</p>
  336. </div>
  337. <table class="params">
  338. <tbody>
  339. <tr>
  340. <td class="name">
  341. <strong>array</strong>
  342. </td>
  343. <td class="description last">
  344. <p>An array holding the RGB values.</p>
  345. </td>
  346. </tr>
  347. <tr>
  348. <td class="name">
  349. <strong>offset</strong>
  350. </td>
  351. <td class="description last">
  352. <p>The offset into the array.</p>
  353. <p>Default is <code>0</code>.</p>
  354. </td>
  355. </tr>
  356. </tbody>
  357. </table>
  358. <dl class="details">
  359. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  360. </dl>
  361. </div>
  362. <h3 class="name name-method" id="fromBufferAttribute" translate="no">.<a href="#fromBufferAttribute">fromBufferAttribute</a><span class="signature">( attribute : <span class="param-type"><a href="BufferAttribute.html">BufferAttribute</a></span>, index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  363. <div class="method">
  364. <div class="description">
  365. <p>Sets the components of this color from the given buffer attribute.</p>
  366. </div>
  367. <table class="params">
  368. <tbody>
  369. <tr>
  370. <td class="name">
  371. <strong>attribute</strong>
  372. </td>
  373. <td class="description last">
  374. <p>The buffer attribute holding color data.</p>
  375. </td>
  376. </tr>
  377. <tr>
  378. <td class="name">
  379. <strong>index</strong>
  380. </td>
  381. <td class="description last">
  382. <p>The index into the attribute.</p>
  383. </td>
  384. </tr>
  385. </tbody>
  386. </table>
  387. <dl class="details">
  388. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  389. </dl>
  390. </div>
  391. <h3 class="name name-method" id="getHSL" translate="no">.<a href="#getHSL">getHSL</a><span class="signature">( target : <span class="param-type">Object</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : Object</span> </h3>
  392. <div class="method">
  393. <div class="description">
  394. <p>Converts the colors RGB values into the HSL format and stores them into the
  395. given target object.</p>
  396. </div>
  397. <table class="params">
  398. <tbody>
  399. <tr>
  400. <td class="name">
  401. <strong>target</strong>
  402. </td>
  403. <td class="description last">
  404. <p>The target object that is used to store the method's result.</p>
  405. </td>
  406. </tr>
  407. <tr>
  408. <td class="name">
  409. <strong>colorSpace</strong>
  410. </td>
  411. <td class="description last">
  412. <p>The color space.</p>
  413. <p>Default is <code>ColorManagement.workingColorSpace</code>.</p>
  414. </td>
  415. </tr>
  416. </tbody>
  417. </table>
  418. <dl class="details">
  419. <dt class="tag-returns"><strong>Returns:</strong> The HSL representation of this color.</dt>
  420. </dl>
  421. </div>
  422. <h3 class="name name-method" id="getHex" translate="no">.<a href="#getHex">getHex</a><span class="signature">( colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : number</span> </h3>
  423. <div class="method">
  424. <div class="description">
  425. <p>Returns the hexadecimal value of this color.</p>
  426. </div>
  427. <table class="params">
  428. <tbody>
  429. <tr>
  430. <td class="name">
  431. <strong>colorSpace</strong>
  432. </td>
  433. <td class="description last">
  434. <p>The color space.</p>
  435. <p>Default is <code>SRGBColorSpace</code>.</p>
  436. </td>
  437. </tr>
  438. </tbody>
  439. </table>
  440. <dl class="details">
  441. <dt class="tag-returns"><strong>Returns:</strong> The hexadecimal value.</dt>
  442. </dl>
  443. </div>
  444. <h3 class="name name-method" id="getHexString" translate="no">.<a href="#getHexString">getHexString</a><span class="signature">( colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  445. <div class="method">
  446. <div class="description">
  447. <p>Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').</p>
  448. </div>
  449. <table class="params">
  450. <tbody>
  451. <tr>
  452. <td class="name">
  453. <strong>colorSpace</strong>
  454. </td>
  455. <td class="description last">
  456. <p>The color space.</p>
  457. <p>Default is <code>SRGBColorSpace</code>.</p>
  458. </td>
  459. </tr>
  460. </tbody>
  461. </table>
  462. <dl class="details">
  463. <dt class="tag-returns"><strong>Returns:</strong> The hexadecimal value as a string.</dt>
  464. </dl>
  465. </div>
  466. <h3 class="name name-method" id="getRGB" translate="no">.<a href="#getRGB">getRGB</a><span class="signature">( target : <span class="param-type"><a href="Color.html">Color</a></span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  467. <div class="method">
  468. <div class="description">
  469. <p>Returns the RGB values of this color and stores them into the given target object.</p>
  470. </div>
  471. <table class="params">
  472. <tbody>
  473. <tr>
  474. <td class="name">
  475. <strong>target</strong>
  476. </td>
  477. <td class="description last">
  478. <p>The target color that is used to store the method's result.</p>
  479. </td>
  480. </tr>
  481. <tr>
  482. <td class="name">
  483. <strong>colorSpace</strong>
  484. </td>
  485. <td class="description last">
  486. <p>The color space.</p>
  487. <p>Default is <code>ColorManagement.workingColorSpace</code>.</p>
  488. </td>
  489. </tr>
  490. </tbody>
  491. </table>
  492. <dl class="details">
  493. <dt class="tag-returns"><strong>Returns:</strong> The RGB representation of this color.</dt>
  494. </dl>
  495. </div>
  496. <h3 class="name name-method" id="getStyle" translate="no">.<a href="#getStyle">getStyle</a><span class="signature">( colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
  497. <div class="method">
  498. <div class="description">
  499. <p>Returns the value of this color as a CSS style string. Example: <code>rgb(255,0,0)</code>.</p>
  500. </div>
  501. <table class="params">
  502. <tbody>
  503. <tr>
  504. <td class="name">
  505. <strong>colorSpace</strong>
  506. </td>
  507. <td class="description last">
  508. <p>The color space.</p>
  509. <p>Default is <code>SRGBColorSpace</code>.</p>
  510. </td>
  511. </tr>
  512. </tbody>
  513. </table>
  514. <dl class="details">
  515. <dt class="tag-returns"><strong>Returns:</strong> The CSS representation of this color.</dt>
  516. </dl>
  517. </div>
  518. <h3 class="name name-method" id="lerp" translate="no">.<a href="#lerp">lerp</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span>, alpha : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  519. <div class="method">
  520. <div class="description">
  521. <p>Linearly interpolates this color's RGB values toward the RGB values of the
  522. given color. The alpha argument can be thought of as the ratio between
  523. the two colors, where <code>0.0</code> is this color and <code>1.0</code> is the first argument.</p>
  524. </div>
  525. <table class="params">
  526. <tbody>
  527. <tr>
  528. <td class="name">
  529. <strong>color</strong>
  530. </td>
  531. <td class="description last">
  532. <p>The color to converge on.</p>
  533. </td>
  534. </tr>
  535. <tr>
  536. <td class="name">
  537. <strong>alpha</strong>
  538. </td>
  539. <td class="description last">
  540. <p>The interpolation factor in the closed interval <code>[0,1]</code>.</p>
  541. </td>
  542. </tr>
  543. </tbody>
  544. </table>
  545. <dl class="details">
  546. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  547. </dl>
  548. </div>
  549. <h3 class="name name-method" id="lerpColors" translate="no">.<a href="#lerpColors">lerpColors</a><span class="signature">( color1 : <span class="param-type"><a href="Color.html">Color</a></span>, color2 : <span class="param-type"><a href="Color.html">Color</a></span>, alpha : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  550. <div class="method">
  551. <div class="description">
  552. <p>Linearly interpolates between the given colors and stores the result in this instance.
  553. The alpha argument can be thought of as the ratio between the two colors, where <code>0.0</code>
  554. is the first and <code>1.0</code> is the second color.</p>
  555. </div>
  556. <table class="params">
  557. <tbody>
  558. <tr>
  559. <td class="name">
  560. <strong>color1</strong>
  561. </td>
  562. <td class="description last">
  563. <p>The first color.</p>
  564. </td>
  565. </tr>
  566. <tr>
  567. <td class="name">
  568. <strong>color2</strong>
  569. </td>
  570. <td class="description last">
  571. <p>The second color.</p>
  572. </td>
  573. </tr>
  574. <tr>
  575. <td class="name">
  576. <strong>alpha</strong>
  577. </td>
  578. <td class="description last">
  579. <p>The interpolation factor in the closed interval <code>[0,1]</code>.</p>
  580. </td>
  581. </tr>
  582. </tbody>
  583. </table>
  584. <dl class="details">
  585. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  586. </dl>
  587. </div>
  588. <h3 class="name name-method" id="lerpHSL" translate="no">.<a href="#lerpHSL">lerpHSL</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span>, alpha : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  589. <div class="method">
  590. <div class="description">
  591. <p>Linearly interpolates this color's HSL values toward the HSL values of the
  592. given color. It differs from <a href="Color.html#lerp">Color#lerp</a> by not interpolating straight
  593. from one color to the other, but instead going through all the hues in between
  594. those two colors. The alpha argument can be thought of as the ratio between
  595. the two colors, where 0.0 is this color and 1.0 is the first argument.</p>
  596. </div>
  597. <table class="params">
  598. <tbody>
  599. <tr>
  600. <td class="name">
  601. <strong>color</strong>
  602. </td>
  603. <td class="description last">
  604. <p>The color to converge on.</p>
  605. </td>
  606. </tr>
  607. <tr>
  608. <td class="name">
  609. <strong>alpha</strong>
  610. </td>
  611. <td class="description last">
  612. <p>The interpolation factor in the closed interval <code>[0,1]</code>.</p>
  613. </td>
  614. </tr>
  615. </tbody>
  616. </table>
  617. <dl class="details">
  618. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  619. </dl>
  620. </div>
  621. <h3 class="name name-method" id="multiply" translate="no">.<a href="#multiply">multiply</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  622. <div class="method">
  623. <div class="description">
  624. <p>Multiplies the RGB values of the given color with the RGB values of this color.</p>
  625. </div>
  626. <table class="params">
  627. <tbody>
  628. <tr>
  629. <td class="name">
  630. <strong>color</strong>
  631. </td>
  632. <td class="description last">
  633. <p>The color to multiply.</p>
  634. </td>
  635. </tr>
  636. </tbody>
  637. </table>
  638. <dl class="details">
  639. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  640. </dl>
  641. </div>
  642. <h3 class="name name-method" id="multiplyScalar" translate="no">.<a href="#multiplyScalar">multiplyScalar</a><span class="signature">( s : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  643. <div class="method">
  644. <div class="description">
  645. <p>Multiplies the given scalar value with the RGB values of this color.</p>
  646. </div>
  647. <table class="params">
  648. <tbody>
  649. <tr>
  650. <td class="name">
  651. <strong>s</strong>
  652. </td>
  653. <td class="description last">
  654. <p>The scalar to multiply.</p>
  655. </td>
  656. </tr>
  657. </tbody>
  658. </table>
  659. <dl class="details">
  660. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  661. </dl>
  662. </div>
  663. <h3 class="name name-method" id="offsetHSL" translate="no">.<a href="#offsetHSL">offsetHSL</a><span class="signature">( h : <span class="param-type">number</span>, s : <span class="param-type">number</span>, l : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  664. <div class="method">
  665. <div class="description">
  666. <p>Adds the given HSL values to this color's values.
  667. Internally, this converts the color's RGB values to HSL, adds HSL
  668. and then converts the color back to RGB.</p>
  669. </div>
  670. <table class="params">
  671. <tbody>
  672. <tr>
  673. <td class="name">
  674. <strong>h</strong>
  675. </td>
  676. <td class="description last">
  677. <p>Hue value between <code>0.0</code> and <code>1.0</code>.</p>
  678. </td>
  679. </tr>
  680. <tr>
  681. <td class="name">
  682. <strong>s</strong>
  683. </td>
  684. <td class="description last">
  685. <p>Saturation value between <code>0.0</code> and <code>1.0</code>.</p>
  686. </td>
  687. </tr>
  688. <tr>
  689. <td class="name">
  690. <strong>l</strong>
  691. </td>
  692. <td class="description last">
  693. <p>Lightness value between <code>0.0</code> and <code>1.0</code>.</p>
  694. </td>
  695. </tr>
  696. </tbody>
  697. </table>
  698. <dl class="details">
  699. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  700. </dl>
  701. </div>
  702. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( r : <span class="param-type">number | string | <a href="Color.html">Color</a></span>, g : <span class="param-type">number</span>, b : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  703. <div class="method">
  704. <div class="description">
  705. <p>Sets the colors's components from the given values.</p>
  706. </div>
  707. <table class="params">
  708. <tbody>
  709. <tr>
  710. <td class="name">
  711. <strong>r</strong>
  712. </td>
  713. <td class="description last">
  714. <p>The red component of the color. If <code>g</code> and <code>b</code> are
  715. not provided, it can be hexadecimal triplet, a CSS-style string or another <code>Color</code> instance.</p>
  716. </td>
  717. </tr>
  718. <tr>
  719. <td class="name">
  720. <strong>g</strong>
  721. </td>
  722. <td class="description last">
  723. <p>The green component.</p>
  724. </td>
  725. </tr>
  726. <tr>
  727. <td class="name">
  728. <strong>b</strong>
  729. </td>
  730. <td class="description last">
  731. <p>The blue component.</p>
  732. </td>
  733. </tr>
  734. </tbody>
  735. </table>
  736. <dl class="details">
  737. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  738. </dl>
  739. </div>
  740. <h3 class="name name-method" id="setColorName" translate="no">.<a href="#setColorName">setColorName</a><span class="signature">( style : <span class="param-type">string</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  741. <div class="method">
  742. <div class="description">
  743. <p>Sets this color from a color name. Faster than <a href="Color.html#setStyle">Color#setStyle</a> if
  744. you don't need the other CSS-style formats.</p>
  745. <p>For convenience, the list of names is exposed in <code>Color.NAMES</code> as a hash.</p>
  746. <pre><code class="language-js">Color.NAMES.aliceblue // returns 0xF0F8FF
  747. </code></pre>
  748. </div>
  749. <table class="params">
  750. <tbody>
  751. <tr>
  752. <td class="name">
  753. <strong>style</strong>
  754. </td>
  755. <td class="description last">
  756. <p>The color name.</p>
  757. </td>
  758. </tr>
  759. <tr>
  760. <td class="name">
  761. <strong>colorSpace</strong>
  762. </td>
  763. <td class="description last">
  764. <p>The color space.</p>
  765. <p>Default is <code>SRGBColorSpace</code>.</p>
  766. </td>
  767. </tr>
  768. </tbody>
  769. </table>
  770. <dl class="details">
  771. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  772. </dl>
  773. </div>
  774. <h3 class="name name-method" id="setFromVector3" translate="no">.<a href="#setFromVector3">setFromVector3</a><span class="signature">( v : <span class="param-type"><a href="Vector3.html">Vector3</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  775. <div class="method">
  776. <div class="description">
  777. <p>Sets the color's RGB components from the given 3D vector.</p>
  778. </div>
  779. <table class="params">
  780. <tbody>
  781. <tr>
  782. <td class="name">
  783. <strong>v</strong>
  784. </td>
  785. <td class="description last">
  786. <p>The vector to set.</p>
  787. </td>
  788. </tr>
  789. </tbody>
  790. </table>
  791. <dl class="details">
  792. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  793. </dl>
  794. </div>
  795. <h3 class="name name-method" id="setHSL" translate="no">.<a href="#setHSL">setHSL</a><span class="signature">( h : <span class="param-type">number</span>, s : <span class="param-type">number</span>, l : <span class="param-type">number</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  796. <div class="method">
  797. <div class="description">
  798. <p>Sets this color from RGB values.</p>
  799. </div>
  800. <table class="params">
  801. <tbody>
  802. <tr>
  803. <td class="name">
  804. <strong>h</strong>
  805. </td>
  806. <td class="description last">
  807. <p>Hue value between <code>0.0</code> and <code>1.0</code>.</p>
  808. </td>
  809. </tr>
  810. <tr>
  811. <td class="name">
  812. <strong>s</strong>
  813. </td>
  814. <td class="description last">
  815. <p>Saturation value between <code>0.0</code> and <code>1.0</code>.</p>
  816. </td>
  817. </tr>
  818. <tr>
  819. <td class="name">
  820. <strong>l</strong>
  821. </td>
  822. <td class="description last">
  823. <p>Lightness value between <code>0.0</code> and <code>1.0</code>.</p>
  824. </td>
  825. </tr>
  826. <tr>
  827. <td class="name">
  828. <strong>colorSpace</strong>
  829. </td>
  830. <td class="description last">
  831. <p>The color space.</p>
  832. <p>Default is <code>ColorManagement.workingColorSpace</code>.</p>
  833. </td>
  834. </tr>
  835. </tbody>
  836. </table>
  837. <dl class="details">
  838. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  839. </dl>
  840. </div>
  841. <h3 class="name name-method" id="setHex" translate="no">.<a href="#setHex">setHex</a><span class="signature">( hex : <span class="param-type">number</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  842. <div class="method">
  843. <div class="description">
  844. <p>Sets this color from a hexadecimal value.</p>
  845. </div>
  846. <table class="params">
  847. <tbody>
  848. <tr>
  849. <td class="name">
  850. <strong>hex</strong>
  851. </td>
  852. <td class="description last">
  853. <p>The hexadecimal value.</p>
  854. </td>
  855. </tr>
  856. <tr>
  857. <td class="name">
  858. <strong>colorSpace</strong>
  859. </td>
  860. <td class="description last">
  861. <p>The color space.</p>
  862. <p>Default is <code>SRGBColorSpace</code>.</p>
  863. </td>
  864. </tr>
  865. </tbody>
  866. </table>
  867. <dl class="details">
  868. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  869. </dl>
  870. </div>
  871. <h3 class="name name-method" id="setRGB" translate="no">.<a href="#setRGB">setRGB</a><span class="signature">( r : <span class="param-type">number</span>, g : <span class="param-type">number</span>, b : <span class="param-type">number</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  872. <div class="method">
  873. <div class="description">
  874. <p>Sets this color from RGB values.</p>
  875. </div>
  876. <table class="params">
  877. <tbody>
  878. <tr>
  879. <td class="name">
  880. <strong>r</strong>
  881. </td>
  882. <td class="description last">
  883. <p>Red channel value between <code>0.0</code> and <code>1.0</code>.</p>
  884. </td>
  885. </tr>
  886. <tr>
  887. <td class="name">
  888. <strong>g</strong>
  889. </td>
  890. <td class="description last">
  891. <p>Green channel value between <code>0.0</code> and <code>1.0</code>.</p>
  892. </td>
  893. </tr>
  894. <tr>
  895. <td class="name">
  896. <strong>b</strong>
  897. </td>
  898. <td class="description last">
  899. <p>Blue channel value between <code>0.0</code> and <code>1.0</code>.</p>
  900. </td>
  901. </tr>
  902. <tr>
  903. <td class="name">
  904. <strong>colorSpace</strong>
  905. </td>
  906. <td class="description last">
  907. <p>The color space.</p>
  908. <p>Default is <code>ColorManagement.workingColorSpace</code>.</p>
  909. </td>
  910. </tr>
  911. </tbody>
  912. </table>
  913. <dl class="details">
  914. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  915. </dl>
  916. </div>
  917. <h3 class="name name-method" id="setScalar" translate="no">.<a href="#setScalar">setScalar</a><span class="signature">( scalar : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  918. <div class="method">
  919. <div class="description">
  920. <p>Sets the colors's components to the given scalar value.</p>
  921. </div>
  922. <table class="params">
  923. <tbody>
  924. <tr>
  925. <td class="name">
  926. <strong>scalar</strong>
  927. </td>
  928. <td class="description last">
  929. <p>The scalar value.</p>
  930. </td>
  931. </tr>
  932. </tbody>
  933. </table>
  934. <dl class="details">
  935. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  936. </dl>
  937. </div>
  938. <h3 class="name name-method" id="setStyle" translate="no">.<a href="#setStyle">setStyle</a><span class="signature">( style : <span class="param-type">string</span>, colorSpace : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  939. <div class="method">
  940. <div class="description">
  941. <p>Sets this color from a CSS-style string. For example, <code>rgb(250, 0,0)</code>,
  942. <code>rgb(100%, 0%, 0%)</code>, <code>hsl(0, 100%, 50%)</code>, <code>#ff0000</code>, <code>#f00</code>, or <code>red</code> ( or
  943. any <a href="https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart" target="_blank" rel="noopener">X11 color name</a> -
  944. all 140 color names are supported).</p>
  945. </div>
  946. <table class="params">
  947. <tbody>
  948. <tr>
  949. <td class="name">
  950. <strong>style</strong>
  951. </td>
  952. <td class="description last">
  953. <p>Color as a CSS-style string.</p>
  954. </td>
  955. </tr>
  956. <tr>
  957. <td class="name">
  958. <strong>colorSpace</strong>
  959. </td>
  960. <td class="description last">
  961. <p>The color space.</p>
  962. <p>Default is <code>SRGBColorSpace</code>.</p>
  963. </td>
  964. </tr>
  965. </tbody>
  966. </table>
  967. <dl class="details">
  968. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  969. </dl>
  970. </div>
  971. <h3 class="name name-method" id="sub" translate="no">.<a href="#sub">sub</a><span class="signature">( color : <span class="param-type"><a href="Color.html">Color</a></span> )</span><span class="type-signature"> : <a href="Color.html">Color</a></span> </h3>
  972. <div class="method">
  973. <div class="description">
  974. <p>Subtracts the RGB values of the given color from the RGB values of this color.</p>
  975. </div>
  976. <table class="params">
  977. <tbody>
  978. <tr>
  979. <td class="name">
  980. <strong>color</strong>
  981. </td>
  982. <td class="description last">
  983. <p>The color to subtract.</p>
  984. </td>
  985. </tr>
  986. </tbody>
  987. </table>
  988. <dl class="details">
  989. <dt class="tag-returns"><strong>Returns:</strong> A reference to this color.</dt>
  990. </dl>
  991. </div>
  992. <h3 class="name name-method" id="toArray" translate="no">.<a href="#toArray">toArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  993. <div class="method">
  994. <div class="description">
  995. <p>Writes the RGB components of this color to the given array. If no array is provided,
  996. the method returns a new instance.</p>
  997. </div>
  998. <table class="params">
  999. <tbody>
  1000. <tr>
  1001. <td class="name">
  1002. <strong>array</strong>
  1003. </td>
  1004. <td class="description last">
  1005. <p>The target array holding the color components.</p>
  1006. <p>Default is <code>[]</code>.</p>
  1007. </td>
  1008. </tr>
  1009. <tr>
  1010. <td class="name">
  1011. <strong>offset</strong>
  1012. </td>
  1013. <td class="description last">
  1014. <p>Index of the first element in the array.</p>
  1015. <p>Default is <code>0</code>.</p>
  1016. </td>
  1017. </tr>
  1018. </tbody>
  1019. </table>
  1020. <dl class="details">
  1021. <dt class="tag-returns"><strong>Returns:</strong> The color components.</dt>
  1022. </dl>
  1023. </div>
  1024. <h3 class="name name-method" id="toJSON" translate="no">.<a href="#toJSON">toJSON</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  1025. <div class="method">
  1026. <div class="description">
  1027. <p>This methods defines the serialization result of this class. Returns the color
  1028. as a hexadecimal value.</p>
  1029. </div>
  1030. <dl class="details">
  1031. <dt class="tag-returns"><strong>Returns:</strong> The hexadecimal value.</dt>
  1032. </dl>
  1033. </div>
  1034. <h2 class="subsection-title">Source</h2>
  1035. <p>
  1036. <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Color.js" translate="no" target="_blank" rel="noopener">src/math/Color.js</a>
  1037. </p>
  1038. </article>
  1039. </section>
  1040. <script src="../scripts/linenumber.js"></script>
  1041. <script src="../scripts/page.js"></script>
  1042. </body>
  1043. </html>
粤ICP备19079148号