Color.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * @author Joe Pea / http://github.com/trusktr
  3. */
  4. export interface HSL {
  5. h: number;
  6. s: number;
  7. l: number;
  8. }
  9. /**
  10. * Represents a color. See also {@link ColorUtils}.
  11. *
  12. * @example
  13. * var color = new THREE.Color( 0xff0000 );
  14. *
  15. * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Color.js">src/math/Color.js</a>
  16. */
  17. export class Color {
  18. constructor( color?: Color | string | number );
  19. constructor( r: number, g: number, b: number );
  20. readonly isColor: true;
  21. /**
  22. * Red channel value between 0 and 1. Default is 1.
  23. */
  24. r: number;
  25. /**
  26. * Green channel value between 0 and 1. Default is 1.
  27. */
  28. g: number;
  29. /**
  30. * Blue channel value between 0 and 1. Default is 1.
  31. */
  32. b: number;
  33. set( color: Color ): Color;
  34. set( color: number ): Color;
  35. set( color: string ): Color;
  36. setScalar( scalar: number ): Color;
  37. setHex( hex: number ): Color;
  38. /**
  39. * Sets this color from RGB values.
  40. * @param r Red channel value between 0 and 1.
  41. * @param g Green channel value between 0 and 1.
  42. * @param b Blue channel value between 0 and 1.
  43. */
  44. setRGB( r: number, g: number, b: number ): Color;
  45. /**
  46. * Sets this color from HSL values.
  47. * Based on MochiKit implementation by Bob Ippolito.
  48. *
  49. * @param h Hue channel value between 0 and 1.
  50. * @param s Saturation value channel between 0 and 1.
  51. * @param l Value channel value between 0 and 1.
  52. */
  53. setHSL( h: number, s: number, l: number ): Color;
  54. /**
  55. * Sets this color from a CSS context style string.
  56. * @param contextStyle Color in CSS context style format.
  57. */
  58. setStyle( style: string ): Color;
  59. /**
  60. * Sets this color from a color name.
  61. * Faster than {@link Color#setStyle .setStyle()} method if you don't need the other CSS-style formats.
  62. * @param style Color name in X11 format.
  63. */
  64. setColorName( style: string ): Color;
  65. /**
  66. * Clones this color.
  67. */
  68. clone(): this;
  69. /**
  70. * Copies given color.
  71. * @param color Color to copy.
  72. */
  73. copy( color: Color ): this;
  74. /**
  75. * Copies given color making conversion from gamma to linear space.
  76. * @param color Color to copy.
  77. */
  78. copyGammaToLinear( color: Color, gammaFactor?: number ): Color;
  79. /**
  80. * Copies given color making conversion from linear to gamma space.
  81. * @param color Color to copy.
  82. */
  83. copyLinearToGamma( color: Color, gammaFactor?: number ): Color;
  84. /**
  85. * Converts this color from gamma to linear space.
  86. */
  87. convertGammaToLinear( gammaFactor?: number ): Color;
  88. /**
  89. * Converts this color from linear to gamma space.
  90. */
  91. convertLinearToGamma( gammaFactor?: number ): Color;
  92. /**
  93. * Copies given color making conversion from sRGB to linear space.
  94. * @param color Color to copy.
  95. */
  96. copySRGBToLinear( color: Color ): Color;
  97. /**
  98. * Copies given color making conversion from linear to sRGB space.
  99. * @param color Color to copy.
  100. */
  101. copyLinearToSRGB( color: Color ): Color;
  102. /**
  103. * Converts this color from sRGB to linear space.
  104. */
  105. convertSRGBToLinear(): Color;
  106. /**
  107. * Converts this color from linear to sRGB space.
  108. */
  109. convertLinearToSRGB(): Color;
  110. /**
  111. * Returns the hexadecimal value of this color.
  112. */
  113. getHex(): number;
  114. /**
  115. * Returns the string formated hexadecimal value of this color.
  116. */
  117. getHexString(): string;
  118. getHSL( target: HSL ): HSL;
  119. /**
  120. * Returns the value of this color in CSS context style.
  121. * Example: rgb(r, g, b)
  122. */
  123. getStyle(): string;
  124. offsetHSL( h: number, s: number, l: number ): this;
  125. add( color: Color ): this;
  126. addColors( color1: Color, color2: Color ): this;
  127. addScalar( s: number ): this;
  128. sub( color: Color ): this;
  129. multiply( color: Color ): this;
  130. multiplyScalar( s: number ): this;
  131. lerp( color: Color, alpha: number ): this;
  132. lerpHSL( color: Color, alpha: number ): this;
  133. equals( color: Color ): boolean;
  134. /**
  135. * Sets this color's red, green and blue value from the provided array.
  136. * @param array the source array.
  137. * @param offset (optional) offset into the array. Default is 0.
  138. */
  139. fromArray( array: number[], offset?: number ): this;
  140. /**
  141. * Sets this color's red, green and blue value from the provided array-like.
  142. * @param array the source array-like.
  143. * @param offset (optional) offset into the array-like. Default is 0.
  144. */
  145. fromArray( array: ArrayLike<number>, offset?: number ): this;
  146. /**
  147. * Returns an array [red, green, blue], or copies red, green and blue into the provided array.
  148. * @param array (optional) array to store the color to. If this is not provided, a new array will be created.
  149. * @param offset (optional) optional offset into the array.
  150. * @return The created or provided array.
  151. */
  152. toArray( array?: number[], offset?: number ): number[];
  153. /**
  154. * Copies red, green and blue into the provided array-like.
  155. * @param array array-like to store the color to.
  156. * @param offset (optional) optional offset into the array-like.
  157. * @return The provided array-like.
  158. */
  159. toArray( xyz: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  160. /**
  161. * List of X11 color names.
  162. */
  163. static NAMES: Record<string, number>;
  164. }