hsl2rgb function

List<num> hsl2rgb (
  1. List<num> color
)

returns a rgb array

Implementation

List<num> hsl2rgb(List<num> color) {
  var h = color[0];
  var s = color[1];
  var l = color[2];

  var r, g, b;

  if (s == 0) {
    r = g = b = l;
  } else {
    var q = (l < 0.5) ? l * (1 + s) : l + s - l * s;

    var p = 2 * l - q;

    r = color2hue(p, q, h + 1 / 3);
    g = color2hue(p, q, h);
    b = color2hue(p, q, h - 1 / 3);
  }

  return [(r * 255).round(), (g * 255).round(), (b * 255).round()];
}