HslColor.random constructor

HslColor.random({
  1. num minHue = 0,
  2. num maxHue = 360,
  3. num minSaturation = 0,
  4. num maxSaturation = 100,
  5. num minLightness = 0,
  6. num maxLightness = 100,
  7. int? seed,
})

Generates a HslColor at random.

minHue and maxHue constrain the generated hue value. If minHue < maxHue, the range will run in a clockwise direction between the two, however if minHue > maxHue, the range will run in a counter-clockwise direction. Both minHue and maxHue must be >= 0 && <= 360 and must not be null.

minSaturation and maxSaturation constrain the generated saturation value.

minLightness and maxLightness constrain the generated lightness value.

Min and max values, besides hues, must be min <= max && max >= min, must be in the range of >= 0 && <= 100, and must not be null.

Implementation

factory HslColor.random({
  num minHue = 0,
  num maxHue = 360,
  num minSaturation = 0,
  num maxSaturation = 100,
  num minLightness = 0,
  num maxLightness = 100,
  int? seed,
}) {
  assert(minHue >= 0 && minHue <= 360);
  assert(maxHue >= 0 && maxHue <= 360);
  assert(minSaturation >= 0 && minSaturation <= maxSaturation);
  assert(maxSaturation >= minSaturation && maxSaturation <= 100);
  assert(minLightness >= 0 && minLightness <= maxLightness);
  assert(maxLightness >= minLightness && maxLightness <= 100);
  return HslColor(
    ColorMath.randomHue(minHue, maxHue, seed),
    ColorMath.random(minSaturation, maxSaturation, seed),
    ColorMath.random(minLightness, maxLightness, seed),
  );
}