ColorPalette.polyad constructor
Generates a ColorPalette by selecting colors with hues
evenly spaced around the color wheel from seed
.
numberOfColors
defaults to 5
, must be > 0
and must
not be null
.
hueVariability
, saturationVariability
, and brightnessVariability
,
if > 0
, add a degree of randomness to the selected color's hue,
saturation, and brightness values, respectively.
hueVariability
defaults to 0
, must be >= 0 && <= 360
,
and must not be null
.
saturationVariability
and brightnessVariability
both default to 0
,
must be >= 0 && <= 100
, and must not be null
.
If perceivedBrightness
is true
, colors will be generated in the
HSP color space. If false
, colors will be generated in the HSB
color space.
If clockwise
is false
, colors will be generated in a clockwise
order around the color wheel. If true
, colors will be generated in a
counter-clockwise order. clockwise
must not be null
.
If growable
is false
, a fixed-length the palette will be constructed
with a fixed-length list. If true
, a growable list will be used instead.
If unique
is false
, the palette will be constructed with a List.
If true
, a uniqueList
will be used instead.
Implementation
factory ColorPalette.polyad(
ColorModel seed, {
int numberOfColors = 5,
num hueVariability = 0,
num saturationVariability = 0,
num brightnessVariability = 0,
bool perceivedBrightness = true,
bool clockwise = true,
bool growable = true,
bool unique = false,
}) {
assert(numberOfColors > 0);
assert(hueVariability >= 0 && hueVariability <= 360);
assert(saturationVariability >= 0 && saturationVariability <= 100);
assert(brightnessVariability >= 0 && brightnessVariability <= 100);
final palette = <ColorModel>[seed];
var distance = 360 / numberOfColors;
if (!clockwise) distance *= -1;
for (var i = 1; i < numberOfColors; i++) {
final color = _generateColor(
seed,
distance * i,
hueVariability,
saturationVariability,
brightnessVariability,
perceivedBrightness,
);
palette.add(color);
}
return ColorPalette(unique
? UniqueList<ColorModel>.from(palette, growable: growable)
: List<ColorModel>.from(palette, growable: growable));
}