Color.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. module( "Color" );
  2. test( "constructor", function(){
  3. var c = new THREE.Color();
  4. ok( c.r, "Red: " + c.r );
  5. ok( c.g, "Green: " + c.g );
  6. ok( c.b, "Blue: " + c.g );
  7. });
  8. test( "copy", function(){
  9. var c = new THREE.Color();
  10. var c2 = new THREE.Color('red');
  11. c.copy(c2);
  12. ok( c.r == 1, "Red c: " + c.r + " Red c2: " + c2.r);
  13. ok( c.g == 0, "Green c: " + c.g + " Green c2: " + c2.g);
  14. ok( c.b == 0, "Blue c: " + c.g + " Blue c2: " + c2.b);
  15. });
  16. test( "setRGB", function(){
  17. var c = new THREE.Color()
  18. c.setRGB(0, 1, 1);
  19. ok( c.r == 0, "Red: " + c.r );
  20. ok( c.g == 1, "Green: " + c.g );
  21. ok( c.b == 1, "Blue: " + c.b );
  22. });
  23. test( "copyGammaToLinear", function(){
  24. var c = new THREE.Color();
  25. var c2 = new THREE.Color();
  26. c2.setRGB(2, 2, 2)
  27. c.copyGammaToLinear(c2)
  28. ok( c.r == 4, "Red c: " + c.r + " Red c2: " + c2.r);
  29. ok( c.g == 4, "Green c: " + c.g + " Green c2: " + c2.g);
  30. ok( c.b == 4, "Blue c: " + c.g + " Blue c2: " + c2.b);
  31. });
  32. test( "copyLinearToGamma", function(){
  33. var c = new THREE.Color();
  34. var c2 = new THREE.Color();
  35. c2.setRGB(4, 4, 4)
  36. c.copyLinearToGamma(c2)
  37. ok( c.r == 2, "Red c: " + c.r + " Red c2: " + c2.r);
  38. ok( c.g == 2, "Green c: " + c.g + " Green c2: " + c2.g);
  39. ok( c.b == 2, "Blue c: " + c.g + " Blue c2: " + c2.b);
  40. });
  41. test( "convertGammaToLinear", function(){
  42. var c = new THREE.Color();
  43. c.setRGB(2, 2, 2)
  44. c.convertGammaToLinear()
  45. ok( c.r == 4, "Red: " + c.r );
  46. ok( c.g == 4, "Green: " + c.g );
  47. ok( c.b == 4, "Blue: " + c.b );
  48. });
  49. test( "convertLinearToGamma", function(){
  50. var c = new THREE.Color();
  51. c.setRGB(4, 4, 4)
  52. c.convertLinearToGamma()
  53. ok( c.r == 2, "Red: " + c.r );
  54. ok( c.g == 2, "Green: " + c.g );
  55. ok( c.b == 2, "Blue: " + c.b );
  56. });
  57. test("setWithNum", function(){
  58. var c = new THREE.Color();
  59. c.set(0xFF0000);
  60. ok( c.r == 1, "Red: " + c.r );
  61. ok( c.g == 0, "Green: " + c.g );
  62. ok( c.b == 0, "Blue: " + c.b );
  63. });
  64. test( "setWithString", function(){
  65. var c = new THREE.Color();
  66. c.set('red');
  67. ok( c.r == 1, "Red: " + c.r );
  68. ok( c.g == 0, "Green: " + c.g );
  69. ok( c.b == 0, "Blue: " + c.b );
  70. });
  71. test( "clone", function(){
  72. var c = new THREE.Color('red');
  73. var c2 = c.clone();
  74. ok( c2.r == 1, "Red c: " + c.r + " Red c2: " + c2.r);
  75. ok( c2.g == 0, "Green c: " + c.g + " Green c2: " + c2.g);
  76. ok( c2.b == 0, "Blue c: " + c.g + " Blue c2: " + c2.b);
  77. });
  78. test( "lerpSelf", function(){
  79. var c = new THREE.Color();
  80. var c2 = new THREE.Color();
  81. c.setRGB(0, 0, 0);
  82. c.lerpSelf(c2, 2);
  83. ok( c.r == 2, "Red: " + c.r );
  84. ok( c.g == 2, "Green: " + c.g );
  85. ok( c.b == 2, "Blue: " + c.b );
  86. });
  87. test( "setStyleRGBRed", function(){
  88. var c = new THREE.Color();
  89. c.setStyle('rgb(255,0,0)');
  90. ok( c.r == 1, "Red: " + c.r );
  91. ok( c.g == 0, "Green: " + c.g );
  92. ok( c.b == 0, "Blue: " + c.b );
  93. });
  94. test( "setStyleRGBPercentRed", function(){
  95. var c = new THREE.Color();
  96. c.setStyle('rgb(100%,0%,0%)');
  97. ok( c.r == 1, "Red: " + c.r );
  98. ok( c.g == 0, "Green: " + c.g );
  99. ok( c.b == 0, "Blue: " + c.b );
  100. });
  101. test( "setStyleHexRed", function(){
  102. var c = new THREE.Color();
  103. c.setStyle('#ff0000');
  104. ok( c.r == 1, "Red: " + c.r );
  105. ok( c.g == 0, "Green: " + c.g );
  106. ok( c.b == 0, "Blue: " + c.b );
  107. });
  108. test( "setStyleHex2Red", function(){
  109. var c = new THREE.Color();
  110. c.setStyle('#f00');
  111. ok( c.r == 1, "Red: " + c.r );
  112. ok( c.g == 0, "Green: " + c.g );
  113. ok( c.b == 0, "Blue: " + c.b );
  114. });
  115. test( "setStyleColorName", function(){
  116. var c = new THREE.Color();
  117. c.setStyle('red');
  118. ok( c.r == 1, "Red: " + c.r );
  119. ok( c.g == 0, "Green: " + c.g );
  120. ok( c.b == 0, "Blue: " + c.b );
  121. });
  122. test( "getHex", function(){
  123. var c = new THREE.Color('red');
  124. var res = c.getHex();
  125. ok( res == 0xFF0000, "Hex: " + res );
  126. });
  127. test( "setHex", function(){
  128. var c = new THREE.Color();
  129. c.setHex(0xFF0000);
  130. ok( c.r == 1, "Red: " + c.r );
  131. ok( c.g == 0, "Green: " + c.g );
  132. ok( c.b == 0, "Blue: " + c.b );
  133. });
  134. test( "getHexString", function(){
  135. var c = new THREE.Color('red');
  136. var res = c.getHexString();
  137. ok( res == 'ff0000', "Hex: " + res );
  138. });
  139. test( "getStyle", function(){
  140. var c = new THREE.Color('red');
  141. var res = c.getStyle();
  142. ok( res == 'rgb(255,0,0)', "style: " + res );
  143. });
  144. test( "getHSV", function(){
  145. var c = new THREE.Color('red');
  146. var hsv = c.getHSV();
  147. ok( hsv.h == 0, "hue: " + hsv.h );
  148. ok( hsv.s == 1, "saturation: " + hsv.s );
  149. ok( hsv.v == 1, "value: " + hsv.v );
  150. });
  151. test( "setHSV", function(){
  152. var c = new THREE.Color();
  153. c.setHSV(0, 1, 1);
  154. var hsv = c.getHSV();
  155. ok( hsv.h == 0, "hue: " + hsv.h );
  156. ok( hsv.s == 1, "saturation: " + hsv.s );
  157. ok( hsv.v == 1, "value: " + hsv.v );
  158. });
  159. // xxx todo more hsv tests