generateHarmony function
- Color base,
- NiceColorHarmony mode, {
- int count = 5,
Generate harmony colors from a base hue.
Implementation
List<Color> generateHarmony(Color base, NiceColorHarmony mode,
{int count = 5}) {
final hsv = HSVColor.fromColor(base);
switch (mode) {
case NiceColorHarmony.complementary:
return [
base,
HSVColor.fromAHSV(1, (hsv.hue + 180) % 360, hsv.saturation, hsv.value)
.toColor(),
];
case NiceColorHarmony.analogous:
return [
HSVColor.fromAHSV(1, (hsv.hue - 30) % 360, hsv.saturation, hsv.value)
.toColor(),
base,
HSVColor.fromAHSV(1, (hsv.hue + 30) % 360, hsv.saturation, hsv.value)
.toColor(),
];
case NiceColorHarmony.triadic:
return [
base,
HSVColor.fromAHSV(1, (hsv.hue + 120) % 360, hsv.saturation, hsv.value)
.toColor(),
HSVColor.fromAHSV(1, (hsv.hue + 240) % 360, hsv.saturation, hsv.value)
.toColor(),
];
case NiceColorHarmony.splitComplementary:
return [
base,
HSVColor.fromAHSV(1, (hsv.hue + 150) % 360, hsv.saturation, hsv.value)
.toColor(),
HSVColor.fromAHSV(1, (hsv.hue + 210) % 360, hsv.saturation, hsv.value)
.toColor(),
];
case NiceColorHarmony.tetradic:
return [
base,
HSVColor.fromAHSV(1, (hsv.hue + 90) % 360, hsv.saturation, hsv.value)
.toColor(),
HSVColor.fromAHSV(1, (hsv.hue + 180) % 360, hsv.saturation, hsv.value)
.toColor(),
HSVColor.fromAHSV(1, (hsv.hue + 270) % 360, hsv.saturation, hsv.value)
.toColor(),
];
case NiceColorHarmony.monochromatic:
return List.generate(
count,
(i) => HSVColor.fromAHSV(
1,
hsv.hue,
hsv.saturation,
(hsv.value * (0.3 + 0.7 * i / (count - 1))).clamp(0.0, 1.0),
).toColor(),
);
}
}