HspColor.random constructor
HspColor.random({})
Generates a HspColor 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.
minPerceivedBrightness
and maxPerceivedBrightness
constrain the
generated perceivedBrightness 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 HspColor.random({
num minHue = 0,
num maxHue = 360,
num minSaturation = 0,
num maxSaturation = 100,
num minPerceivedBrightness = 0,
num maxPerceivedBrightness = 100,
int? seed,
}) {
assert(minHue >= 0 && minHue <= 360);
assert(maxHue >= 0 && maxHue <= 360);
assert(minSaturation >= 0 && minSaturation <= maxSaturation);
assert(maxSaturation >= minSaturation && maxSaturation <= 100);
assert(minPerceivedBrightness >= 0 &&
minPerceivedBrightness <= maxPerceivedBrightness);
assert(maxPerceivedBrightness >= minPerceivedBrightness &&
maxPerceivedBrightness <= 100);
return HspColor(
ColorMath.randomHue(minHue, maxHue, seed),
ColorMath.random(minSaturation, maxSaturation, seed),
ColorMath.random(minPerceivedBrightness, maxPerceivedBrightness, seed),
);
}