Color.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. isColor: boolean;
  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. * Clones this color.
  61. */
  62. clone(): this;
  63. /**
  64. * Copies given color.
  65. * @param color Color to copy.
  66. */
  67. copy( color: Color ): this;
  68. /**
  69. * Copies given color making conversion from gamma to linear space.
  70. * @param color Color to copy.
  71. */
  72. copyGammaToLinear( color: Color, gammaFactor?: number ): Color;
  73. /**
  74. * Copies given color making conversion from linear to gamma space.
  75. * @param color Color to copy.
  76. */
  77. copyLinearToGamma( color: Color, gammaFactor?: number ): Color;
  78. /**
  79. * Converts this color from gamma to linear space.
  80. */
  81. convertGammaToLinear( gammaFactor?: number ): Color;
  82. /**
  83. * Converts this color from linear to gamma space.
  84. */
  85. convertLinearToGamma( gammaFactor?: number ): Color;
  86. /**
  87. * Copies given color making conversion from sRGB to linear space.
  88. * @param color Color to copy.
  89. */
  90. copySRGBToLinear( color: Color ): Color;
  91. /**
  92. * Copies given color making conversion from linear to sRGB space.
  93. * @param color Color to copy.
  94. */
  95. copyLinearToSRGB( color: Color ): Color;
  96. /**
  97. * Converts this color from sRGB to linear space.
  98. */
  99. convertSRGBToLinear(): Color;
  100. /**
  101. * Converts this color from linear to sRGB space.
  102. */
  103. convertLinearToSRGB(): Color;
  104. /**
  105. * Returns the hexadecimal value of this color.
  106. */
  107. getHex(): number;
  108. /**
  109. * Returns the string formated hexadecimal value of this color.
  110. */
  111. getHexString(): string;
  112. getHSL( target: HSL ): HSL;
  113. /**
  114. * Returns the value of this color in CSS context style.
  115. * Example: rgb(r, g, b)
  116. */
  117. getStyle(): string;
  118. offsetHSL( h: number, s: number, l: number ): this;
  119. add( color: Color ): this;
  120. addColors( color1: Color, color2: Color ): this;
  121. addScalar( s: number ): this;
  122. sub( color: Color ): this;
  123. multiply( color: Color ): this;
  124. multiplyScalar( s: number ): this;
  125. lerp( color: Color, alpha: number ): this;
  126. lerpHSL( color: Color, alpha: number ): this;
  127. equals( color: Color ): boolean;
  128. /**
  129. * Sets this color's red, green and blue value from the provided array.
  130. * @param array the source array.
  131. * @param offset (optional) offset into the array. Default is 0.
  132. */
  133. fromArray( array: number[], offset?: number ): this;
  134. /**
  135. * Sets this color's red, green and blue value from the provided array-like.
  136. * @param array the source array-like.
  137. * @param offset (optional) offset into the array-like. Default is 0.
  138. */
  139. fromArray( array: ArrayLike<number>, offset?: number ): this;
  140. /**
  141. * Returns an array [red, green, blue], or copies red, green and blue into the provided array.
  142. * @param array (optional) array to store the color to. If this is not provided, a new array will be created.
  143. * @param offset (optional) optional offset into the array.
  144. * @return The created or provided array.
  145. */
  146. toArray( array?: number[], offset?: number ): number[];
  147. /**
  148. * Copies red, green and blue into the provided array-like.
  149. * @param array array-like to store the color to.
  150. * @param offset (optional) optional offset into the array-like.
  151. * @return The provided array-like.
  152. */
  153. toArray( xyz: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  154. }