Color.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div class="desc">
  13. Represents a color.
  14. </div>
  15. <h2>Example</h2>
  16. <code>var color = new THREE.Color();</code>
  17. <code>var color = new THREE.Color( 0xff0000 );</code>
  18. <code>var color = new THREE.Color("rgb(255, 0, 0)");</code>
  19. <code>var color = new THREE.Color("rgb(100%, 0%, 0%)");</code>
  20. <code>var color = new THREE.Color("hsl(0, 100%, 50%)");</code>
  21. <code>var color = new THREE.Color( 1, 0, 0 );</code>
  22. <h2>Constructor</h2>
  23. <h3>[name]( r, g, b )</h3>
  24. <div>
  25. r - the red component of the color if arguments g and b are defined. If they are not defined, it can be a hexadecimal or a CSS-style string or a Color instance.<br />
  26. g - The green component of the color if it is defined.<br />
  27. b - The blue component of the color if it is defined.
  28. </div>
  29. <div>
  30. All arguments are optional. The default color is White.<br />
  31. When all arguments are defined then r is the red component, g is the green component and b is the blue component of the color.<br />
  32. When only r is defined:<br />
  33. <ul>
  34. <li>It can be a hexadecimal of the color.</li>
  35. <li>It can be an another color instance.</li>
  36. <li>It can be a CSS style. For Instance:
  37. <ul>
  38. <li>rgb(250, 0,0)</li>
  39. <li>rgb(100%,0%,0%)</li>
  40. <li>hsl(0, 100%, 50%)</li>
  41. <li>#ff0000</li>
  42. <li>#f00</li>
  43. <li>red</li>
  44. </ul>
  45. </li>
  46. </ul>
  47. </div>
  48. <h2>Properties</h2>
  49. <h3>[property:Float r]</h3>
  50. <div>
  51. Red channel value between 0 and 1. Default is 1.
  52. </div>
  53. <h3>[property:Float g]</h3>
  54. <div>
  55. Green channel value between 0 and 1. Default is 1.
  56. </div>
  57. <h3>[property:Float b]</h3>
  58. <div>
  59. Blue channel value between 0 and 1. Default is 1.
  60. </div>
  61. <h2>Methods</h2>
  62. <h3>[method:Color set]( value ) [page:Color this]</h3>
  63. <div>
  64. value -- either an instance of [page:Color], a [page:Integer hexadecimal] value, or a css style [page:String string]
  65. </div>
  66. <div>
  67. Delegates to .copy, .setStyle, or .setHex depending on input type.
  68. </div>
  69. <h3>[method:Color copy]( [page:Color color] ) [page:Color this]</h3>
  70. <div>
  71. color — Color to copy.
  72. </div>
  73. <div>
  74. Copies given color.
  75. </div>
  76. <h3>[method:Color fromArray]([page:Array array], [page:Integer offset]) [page:Color this]</h3>
  77. <div>
  78. array -- [page:Array] [r, g, b] <br />
  79. offset -- [page:Integer] An optional offset into the array.
  80. </div>
  81. <div>
  82. Sets this color's components based on an array formatted like [r, g, b]
  83. </div>
  84. <h3>[method:Color copyGammaToLinear]( [page:Color color] ) [page:Color this]</h3>
  85. <div>
  86. color — Color to copy.
  87. </div>
  88. <div>
  89. Copies given color making conversion from gamma to linear space.
  90. </div>
  91. <h3>[method:Color copyLinearToGamma]( [page:Color color] ) [page:Color this]</h3>
  92. <div>
  93. color — Color to copy.
  94. </div>
  95. <div>
  96. Copies given color making conversion from linear to gamma space.
  97. </div>
  98. <h3>[method:Color convertGammaToLinear]() [page:Color this]</h3>
  99. <div>
  100. Converts this color from gamma to linear space.
  101. </div>
  102. <h3>[method:Color convertLinearToGamma]() [page:Color this]</h3>
  103. <div>
  104. Converts this color from linear to gamma space.
  105. </div>
  106. <h3>[method:Color setRGB]( [page:Float r], [page:Float g], [page:Float b] ) [page:Color this]</h3>
  107. <div>
  108. r — Red channel value between 0 and 1.<br />
  109. g — Green channel value between 0 and 1.<br />
  110. b — Blue channel value between 0 and 1.
  111. </div>
  112. <div>
  113. Sets this color from RGB values.
  114. </div>
  115. <h3>[method:Integer getHex]()</h3>
  116. <div>
  117. Returns the hexadecimal value of this color.
  118. </div>
  119. <h3>[method:String getHexString]()</h3>
  120. <div>
  121. Returns the string formated hexadecimal value of this color.
  122. </div>
  123. <h3>[method:Color setHex]( [page:Integer hex] ) [page:Color this]</h3>
  124. <div>
  125. hex — Color in hexadecimal.<br />
  126. </div>
  127. <div>
  128. Sets this color from a hexadecimal value.
  129. </div>
  130. <h3>[method:Color setStyle]( [page:String style] ) [page:Color this]</h3>
  131. <div>
  132. style — color as a CSS-style string.
  133. </div>
  134. <div>
  135. Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red". Transluent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel coordinate will be discarded.
  136. </div>
  137. <h3>[method:String getStyle]()</h3>
  138. <div>
  139. Returns the value of this color as a CSS-style string. Example: rgb(255,0,0)
  140. </div>
  141. <h3>[method:Color setHSL]( [page:Float h], [page:Float s], [page:Float l] ) [page:Color this]</h3>
  142. <div>
  143. h — hue value between 0.0 and 1.0 <br />
  144. s — saturation value between 0.0 and 1.0 <br />
  145. l — lightness value between 0.0 and 1.0
  146. </div>
  147. <div>
  148. Sets color from hsl
  149. </div>
  150. <h3>.getHSL() [page:Object hsl]</h3>
  151. <div>
  152. Returns an object with properties h, s, and l.
  153. </div>
  154. <h3>[method:Color offsetHSL]( [page:Float h], [page:Float s], [page:Float l] ) [page:Color this]</h3>
  155. <div>
  156. Adds given h, s, and l to this color's existing h, s, and l values.
  157. </div>
  158. <h3>[method:Color add]( [page:Color color] ) [page:Color this]</h3>
  159. <div>
  160. Adds rgb values of given color to rgb values of this color
  161. </div>
  162. <h3>[method:Color addColors]( [page:Color color1], [page:Color color2] ) [page:Color this]</h3>
  163. <div>
  164. Sets this color to the sum of color1 and color2
  165. </div>
  166. <h3>[method:Color addScalar]( [page:Number s] ) [page:Color this]</h3>
  167. <div>
  168. Adds s to the rgb values of this color
  169. </div>
  170. <h3>[method:Color multiply]( [page:Color color] ) [page:Color this]</h3>
  171. <div>
  172. Multiplies this color's rgb values by given color's rgb values
  173. </div>
  174. <h3>[method:Color multiplyScalar]( [page:Number s] ) [page:Color this]</h3>
  175. <div>
  176. Multiplies this color's rgb values by s
  177. </div>
  178. <h3>[method:Color lerp]( [page:Color color], alpha ) [page:Color this]</h3>
  179. <div>
  180. alpha -- a number between 0 and 1.
  181. </div>
  182. <div>
  183. Linear interpolation of this colors rgb values and the rgb values of the first argument. The alpha argument can be thought of as the percent between the two colors, where 0 is this color and 1 is the first argument.
  184. </div>
  185. <h3>[method:Color equals]( [page:Color c] ) [page:Color this]</h3>
  186. <div>
  187. Compares this color and c and returns true if they are the same, false otherwise.
  188. </div>
  189. <h3>[method:Color clone]() [page:Color this]</h3>
  190. <div>
  191. Clones this color.
  192. </div>
  193. <h3>[method:Array toArray]([page:Array array], [page:Integer offset]) [page:Color this]</h3>
  194. <div>
  195. array -- An optional array to store the color to. <br />
  196. offset -- An optional offset into the array.
  197. </div>
  198. <div>
  199. Returns an array [r,g,b]
  200. </div>
  201. <h2>Source</h2>
  202. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  203. </body>
  204. </html>