Color.d.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. export interface HSL {
  2. h: number;
  3. s: number;
  4. l: number;
  5. }
  6. /**
  7. * Represents a color. See also {@link ColorUtils}.
  8. *
  9. * @example
  10. * var color = new THREE.Color( 0xff0000 );
  11. *
  12. * @see <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Color.js">src/math/Color.js</a>
  13. */
  14. export class Color {
  15. constructor( color?: Color | string | number );
  16. constructor( r: number, g: number, b: number );
  17. isColor: boolean;
  18. /**
  19. * Red channel value between 0 and 1. Default is 1.
  20. */
  21. r: number;
  22. /**
  23. * Green channel value between 0 and 1. Default is 1.
  24. */
  25. g: number;
  26. /**
  27. * Blue channel value between 0 and 1. Default is 1.
  28. */
  29. b: number;
  30. set( color: Color ): Color;
  31. set( color: number ): Color;
  32. set( color: string ): Color;
  33. setScalar( scalar: number ): Color;
  34. setHex( hex: number ): Color;
  35. /**
  36. * Sets this color from RGB values.
  37. * @param r Red channel value between 0 and 1.
  38. * @param g Green channel value between 0 and 1.
  39. * @param b Blue channel value between 0 and 1.
  40. */
  41. setRGB( r: number, g: number, b: number ): Color;
  42. /**
  43. * Sets this color from HSL values.
  44. * Based on MochiKit implementation by Bob Ippolito.
  45. *
  46. * @param h Hue channel value between 0 and 1.
  47. * @param s Saturation value channel between 0 and 1.
  48. * @param l Value channel value between 0 and 1.
  49. */
  50. setHSL( h: number, s: number, l: number ): Color;
  51. /**
  52. * Sets this color from a CSS context style string.
  53. * @param contextStyle Color in CSS context style format.
  54. */
  55. setStyle( style: string ): Color;
  56. /**
  57. * Clones this color.
  58. */
  59. clone(): this;
  60. /**
  61. * Copies given color.
  62. * @param color Color to copy.
  63. */
  64. copy( color: Color ): this;
  65. /**
  66. * Copies given color making conversion from gamma to linear space.
  67. * @param color Color to copy.
  68. */
  69. copyGammaToLinear( color: Color, gammaFactor?: number ): Color;
  70. /**
  71. * Copies given color making conversion from linear to gamma space.
  72. * @param color Color to copy.
  73. */
  74. copyLinearToGamma( color: Color, gammaFactor?: number ): Color;
  75. /**
  76. * Converts this color from gamma to linear space.
  77. */
  78. convertGammaToLinear(): Color;
  79. /**
  80. * Converts this color from linear to gamma space.
  81. */
  82. convertLinearToGamma(): Color;
  83. /**
  84. * Copies given color making conversion from sRGB to linear space.
  85. * @param color Color to copy.
  86. */
  87. copySRGBToLinear(): Color;
  88. /**
  89. * Copies given color making conversion from linear to sRGB space.
  90. * @param color Color to copy.
  91. */
  92. copyLinearToSRGB(): Color;
  93. /**
  94. * Converts this color from sRGB to linear space.
  95. */
  96. convertSRGBToLinear(): Color;
  97. /**
  98. * Converts this color from linear to sRGB space.
  99. */
  100. convertLinearToSRGB(): Color;
  101. /**
  102. * Returns the hexadecimal value of this color.
  103. */
  104. getHex(): number;
  105. /**
  106. * Returns the string formated hexadecimal value of this color.
  107. */
  108. getHexString(): string;
  109. getHSL( target: HSL ): HSL;
  110. /**
  111. * Returns the value of this color in CSS context style.
  112. * Example: rgb(r, g, b)
  113. */
  114. getStyle(): string;
  115. offsetHSL( h: number, s: number, l: number ): this;
  116. add( color: Color ): this;
  117. addColors( color1: Color, color2: Color ): this;
  118. addScalar( s: number ): this;
  119. sub( color: Color ): this;
  120. multiply( color: Color ): this;
  121. multiplyScalar( s: number ): this;
  122. lerp( color: Color, alpha: number ): this;
  123. lerpHSL( color: Color, alpha: number ): this;
  124. equals( color: Color ): boolean;
  125. fromArray( rgb: number[], offset?: number ): this;
  126. toArray( array?: number[], offset?: number ): number[];
  127. toArray( xyz: ArrayLike<number>, offset?: number ): ArrayLike<number>;
  128. }