ColorPalette.random constructor
- int numberOfColors, {
- ColorSpace colorSpace = ColorSpace.rgb,
- num minHue = 0,
- num maxHue = 360,
- num minSaturation = 0,
- num maxSaturation = 100,
- num minBrightness = 0,
- num maxBrightness = 100,
- bool perceivedBrightness = true,
- bool distributeHues = true,
- num? distributionVariability,
- bool clockwise = true,
- bool growable = true,
- bool unique = false,
Generates a ColorPalette with numberOfColors
at random, constrained
within the specified hue, saturation, and brightness ranges.
minHue
and maxHue
are used to set the range of hues that will be
selected from. 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
are used to set the range of the
generated colors' saturation values. minSaturation
must be
<= maxSaturation
and maxSaturation
must be >= minSaturation
.
Both minSaturation
and maxSaturation
must be >= 0 && <= 100
.
minBrightness
and maxBrightness
are used to set the range of the
generated colors' percieved brightness values. minBrightness
must be
<= maxBrightness
and maxBrightness
must be >= minBrightness
.
Both minBrightness
and maxBrightness
must be >= 0 && <= 100
.
If distributeHues
is true
, the generated colors will be spread
evenly across the range of hues allowed for. distributeHues
must
not be null
.
distributionVariability
will add a degree of randomness to the selected
hues, if distributeHues
is true
. If null
, distributionVariability
defaults to (minHue - maxHue).abs() / numberOfColors / 4
. To allow for
no variability at all, distributionVariability
must be set to 0
.
colorSpace
defines the color space colors will be generated and
returned in. colorSpace
defaults to ColorSpace.rgb and must not
be null
.
Implementation
factory ColorPalette.random(
int numberOfColors, {
ColorSpace colorSpace = ColorSpace.rgb,
num minHue = 0,
num maxHue = 360,
num minSaturation = 0,
num maxSaturation = 100,
num minBrightness = 0,
num maxBrightness = 100,
bool perceivedBrightness = true,
bool distributeHues = true,
num? distributionVariability,
bool clockwise = true,
bool growable = true,
bool unique = false,
}) {
assert(numberOfColors > 0);
assert(minHue >= 0 && minHue <= 360);
assert(maxHue >= 0 && maxHue <= 360);
assert(minSaturation >= 0 && minSaturation <= maxSaturation);
assert(maxSaturation >= minSaturation && maxSaturation <= 100);
assert(minBrightness >= 0 && minBrightness <= maxBrightness);
assert(maxBrightness >= minBrightness && maxBrightness <= 100);
return ColorPalette(_cast(
cp.ColorPalette.random(
numberOfColors,
colorSpace: colorSpace,
minHue: minHue,
maxHue: maxHue,
minSaturation: minSaturation,
maxSaturation: maxSaturation,
minBrightness: minBrightness,
maxBrightness: maxBrightness,
perceivedBrightness: perceivedBrightness,
distributeHues: distributeHues,
distributionVariability: distributionVariability,
clockwise: clockwise,
),
growable: growable,
unique: unique,
));
}