fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static float hueToRGB(float m1, float m2, float h) {
  11. if(h < 0) {
  12. h += 1.0f;
  13. } else if(h > 1.0f) {
  14. h -= 1.0f;
  15. }
  16.  
  17. if((h * 6) < 1) {
  18. return m1 + (m2 - m1) * 6 * h;
  19. } else if((h * 2) < 1) {
  20. return m2;
  21. } else if((h * 3) < 2) {
  22. return m1 + (m2 - m1) * ((2.0f / 3.0f) - h) * 6;
  23. } else {
  24. return m1;
  25. }
  26. }
  27.  
  28. public static void main(String[] args) {
  29. float h = 180.0f / 360.0f;
  30. float s = 100.0f / 100.0f;
  31. float l = 38.0f / 100.0f;
  32. float r = 0;
  33. float g = 0;
  34. float b = 0;
  35.  
  36. if(s == 0.0) {
  37. r = g = b = l;
  38. } else {
  39. float m2 = l < 0.5 ? l * (1 + s) : (l + s) - (l * s);
  40. float m1 = (l * 2) - m2;
  41.  
  42. r = hueToRGB(m1, m2, h + (1.0f / 3.0f));
  43. g = hueToRGB(m1, m2, h);
  44. b = hueToRGB(m1, m2, h - (1.0f / 3.0f));
  45. }
  46.  
  47. System.out.printf("%.2f %.2f %.2f -> %.2f %.2f %.2f",
  48. h, s, l,
  49. r, g, b);
  50. }
  51.  
  52. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
0.50 1.00 0.38 -> 0.00 0.76 0.76