Java HSL Color Convert hsl2rgb(float h, float s, float l)

Here you can find the source of hsl2rgb(float h, float s, float l)

Description

hslrgb

License

Open Source License

Declaration

public static int[] hsl2rgb(float h, float s, float l) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[] hsl2rgb(float h, float s, float l) {
        float c = (1 - Math.abs(2 * l - 1)) * s;
        float x = c * (1 - Math.abs((h / 60) % 2 - 1));
        float m = l - c / 2;

        float r1 = 0, g1 = 0, b1 = 0;

        if (h < 60) {
            r1 = c;/*from ww  w  .  j  a v a 2 s .  c  om*/
            g1 = x;
            b1 = 0;
        } else if (h >= 60 && h < 120) {
            r1 = x;
            g1 = c;
            b1 = 0;
        } else if (h >= 120 && h < 180) {
            r1 = 0;
            g1 = c;
            b1 = x;
        } else if (h >= 180 && h < 240) {
            r1 = 0;
            g1 = x;
            b1 = c;
        } else if (h >= 240 && h < 300) {
            r1 = x;
            g1 = 0;
            b1 = c;
        } else if (h >= 300 && h < 360) {
            r1 = c;
            g1 = 0;
            b1 = x;
        }

        return new int[] { (int) ((r1 + m) * 255), (int) ((g1 + m) * 255), (int) ((b1 + m) * 255) };
    }
}

Related

  1. findHue(Color color)
  2. hsl2hex(int[] hsl)
  3. hsl2rgb(double h, double s, double l)
  4. hsl2rgb(int[] hsl)
  5. hsla_hue(double h, double m1, double m2)
  6. hslToHsb(float[] inputHsl)
  7. HSLtoRGB(double h, double s, double l)