ColorPalette.adjacent constructor
Generates a ColorPalette by selecting colors with hues
to both sides of seed
's hue value.
If numberOfColors
is odd, seed
will be included in the palette.
If even, seed
will be excluded from the palette. numberOfColors
defaults to 5
, must be > 0
, and must not be null
.
distance
is the base spacing between the selected colors' hue values.
distance
defaults to 30
degrees 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 growable
is false
, the palette will be constructed with a
fixed-length list, numberOfColors
in length. If true
, a growable
palette will be constructed instead.
If unique
is false
, the palette will be constructed with a List.
If true
, a uniqueList
will be used instead, requiring all colors
in the palette be unique.
Implementation
factory ColorPalette.adjacent(
ColorModel seed, {
int numberOfColors = 5,
num distance = 30,
num hueVariability = 0,
num saturationVariability = 0,
num brightnessVariability = 0,
bool perceivedBrightness = 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>[];
var colorsRemaining = numberOfColors;
if (numberOfColors.isOdd) {
palette.add(seed);
colorsRemaining -= 1;
}
for (var i = 1; i <= colorsRemaining; i++) {
final color = _generateColor(
seed,
(i % 2 == 0 ? distance * -1 : distance) * ((i / 2).ceil()),
hueVariability,
saturationVariability,
brightnessVariability,
perceivedBrightness,
);
palette.add(color);
}
return ColorPalette(unique
? UniqueList<ColorModel>.from(palette, growable: growable)
: List<ColorModel>.from(palette, growable: growable));
}