Color.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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( "copyHex", function(){
  9. var c = new THREE.Color();
  10. var c2 = new THREE.Color(0xF5FFFA);
  11. c.copy(c2);
  12. ok(c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex());
  13. });
  14. test( "copyColorString", function(){
  15. var c = new THREE.Color();
  16. var c2 = new THREE.Color('ivory');
  17. c.copy(c2);
  18. ok(c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex());
  19. });
  20. test( "setRGB", function(){
  21. var c = new THREE.Color()
  22. c.setRGB(255, 2, 1);
  23. ok( c.r == 255, "Red: " + c.r );
  24. ok( c.g == 2, "Green: " + c.g );
  25. ok( c.b == 1, "Blue: " + c.b );
  26. });
  27. test( "copyGammaToLinear", function(){
  28. var c = new THREE.Color();
  29. var c2 = new THREE.Color();
  30. c2.setRGB(2, 4, 8)
  31. c.copyGammaToLinear(c2)
  32. ok( c.r == 4, "Red c: " + c.r + " Red c2: " + c2.r);
  33. ok( c.g == 16, "Green c: " + c.g + " Green c2: " + c2.g);
  34. ok( c.b == 64, "Blue c: " + c.b + " Blue c2: " + c2.b);
  35. });
  36. test( "copyLinearToGamma", function(){
  37. var c = new THREE.Color();
  38. var c2 = new THREE.Color();
  39. c2.setRGB(4, 9, 16)
  40. c.copyLinearToGamma(c2)
  41. ok( c.r == 2, "Red c: " + c.r + " Red c2: " + c2.r);
  42. ok( c.g == 3, "Green c: " + c.g + " Green c2: " + c2.g);
  43. ok( c.b == 4, "Blue c: " + c.b + " Blue c2: " + c2.b);
  44. });
  45. test( "convertGammaToLinear", function(){
  46. var c = new THREE.Color();
  47. c.setRGB(2, 4, 8)
  48. c.convertGammaToLinear()
  49. ok( c.r == 4, "Red: " + c.r );
  50. ok( c.g == 16, "Green: " + c.g );
  51. ok( c.b == 64, "Blue: " + c.b );
  52. });
  53. test( "convertLinearToGamma", function(){
  54. var c = new THREE.Color();
  55. c.setRGB(4, 9, 16)
  56. c.convertLinearToGamma()
  57. ok( c.r == 2, "Red: " + c.r );
  58. ok( c.g == 3, "Green: " + c.g );
  59. ok( c.b == 4, "Blue: " + c.b );
  60. });
  61. test("setWithNum", function(){
  62. var c = new THREE.Color();
  63. c.set(0xFF0000);
  64. ok( c.r == 1, "Red: " + c.r );
  65. ok( c.g == 0, "Green: " + c.g );
  66. ok( c.b == 0, "Blue: " + c.b );
  67. });
  68. test( "setWithString", function(){
  69. var c = new THREE.Color();
  70. c.set('silver');
  71. ok(c.getHex() == 0xC0C0C0, "Hex c: " + c.getHex());
  72. });
  73. test( "clone", function(){
  74. var c = new THREE.Color('teal');
  75. var c2 = c.clone();
  76. ok(c2.getHex() == 0x008080, "Hex c2: " + c2.getHex());
  77. });
  78. test( "lerp", function(){
  79. var c = new THREE.Color();
  80. var c2 = new THREE.Color();
  81. c.setRGB(0, 0, 0);
  82. c.lerp(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( "setStyleRGBPercent", function(){
  95. var c = new THREE.Color();
  96. c.setStyle('rgb(100%,50%,10%)');
  97. ok( c.r == 1, "Red: " + c.r );
  98. ok( c.g == 0.5, "Green: " + c.g );
  99. ok( c.b == 0.1, "Blue: " + c.b );
  100. });
  101. test( "setStyleHexSkyBlue", function(){
  102. var c = new THREE.Color();
  103. c.setStyle('#87CEEB');
  104. ok(c.getHex() == 0x87CEEB, "Hex c: " + c.getHex());
  105. });
  106. test( "setStyleHex2Olive", function(){
  107. var c = new THREE.Color();
  108. c.setStyle('#F00');
  109. ok(c.getHex() == 0xFF0000, "Hex c: " + c.getHex());
  110. });
  111. test( "setStyleColorName", function(){
  112. var c = new THREE.Color();
  113. c.setStyle('powderblue');
  114. ok(c.getHex() == 0xB0E0E6, "Hex c: " + c.getHex());
  115. });
  116. test( "getHex", function(){
  117. var c = new THREE.Color('red');
  118. var res = c.getHex();
  119. ok( res == 0xFF0000, "Hex: " + res );
  120. });
  121. test( "setHex", function(){
  122. var c = new THREE.Color();
  123. c.setHex(0xFA8072);
  124. ok( c.getHex() == 0xFA8072, "Hex: " + c.getHex());
  125. });
  126. test( "getHexString", function(){
  127. var c = new THREE.Color('tomato');
  128. var res = c.getHexString();
  129. ok( res == 'ff6347', "Hex: " + res );
  130. });
  131. test( "getStyle", function(){
  132. var c = new THREE.Color('plum');
  133. var res = c.getStyle();
  134. ok( res == 'rgb(221,160,221)', "style: " + res );
  135. });
  136. test( "getHSL", function () {
  137. var c = new THREE.Color( 0x80ffff );
  138. var hsl = c.getHSL();
  139. ok( hsl.h == 0.5, "hue: " + hsl.h );
  140. ok( hsl.s == 1.0, "saturation: " + hsl.s );
  141. ok( (Math.round(parseFloat(hsl.l)*100)/100) == 0.75, "lightness: " + hsl.l );
  142. });
  143. test( "setHSL", function () {
  144. var c = new THREE.Color();
  145. c.setHSL(0.75, 1.0, 0.25);
  146. var hsl = c.getHSL();
  147. ok( hsl.h == 0.75, "hue: " + hsl.h );
  148. ok( hsl.s == 1.00, "saturation: " + hsl.s );
  149. ok( hsl.l == 0.25, "lightness: " + hsl.l );
  150. });