Color.d.ts 5.0 KB

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