Here you can find the source of HSLtoRGB(double h, double s, double l)
Parameter | Description |
---|---|
h | red value |
s | green value |
l | blue value |
public static int[] HSLtoRGB(double h, double s, double l)
//package com.java2s; //License from project: LGPL public class Main { /**/*from w ww. j a v a 2s.c om*/ * Converts HSL to RGB. * HSL values are in decimal form: <br> * H: 360 = 1, <br> * S: 100 = 1, <br> * L: 100 = 1. <br> * Thanks to http://serennu.com/colour/rgbtohsl.php for help on this calculation. * * @param h red value * @param s green value * @param l blue value * @return Array containing RGB values in the format {r,g,b} */ public static int[] HSLtoRGB(double h, double s, double l) { int r; int g; int b; double var1; double var2; if (s == 0) { r = (int) (l * 255); g = (int) (l * 255); b = (int) (l * 255); } else { if (l < 0.5) { var2 = l * (1 + s); } else { var2 = (l + s) - (s * l); } var1 = 2 * l - var2; r = (int) (255 * HueToRGB(var1, var2, h + (1.0 / 3.0))); g = (int) (255 * HueToRGB(var1, var2, h)); b = (int) (255 * HueToRGB(var1, var2, h - (1.0 / 3.0))); } int[] rgb = new int[3]; rgb[0] = r; rgb[1] = g; rgb[2] = b; return rgb; } public static double HueToRGB(double v1, double v2, double vh) { if (vh < 0) { vh += 1; } if (vh > 1) { vh -= 1; } if ((6 * vh) < 1) { return (v1 + (v2 - v1) * 6 * vh); } if ((2 * vh) < 1) { return (v2); } if ((3 * vh) < 2) { return (v1 + (v2 - v1) * ((2.0 / 3.0 - vh) * 6)); } return v1; } }