colorFromHsv function
Aus Farbton, Sättigung und Helligkeit (HSV) eine Farbe.
hue in Grad (0–360), saturation und luminance von 0 bis 1. Gebraucht
für eine freie Farbwahl: ein Regler je Größe ist begreiflicher als sechs
Hexzeichen.
Implementation
PosColor colorFromHsv(double hue, double saturation, double value) {
final h = (hue % 360 + 360) % 360;
final s = saturation.clamp(0.0, 1.0);
final v = value.clamp(0.0, 1.0);
final c = v * s;
final x = c * (1 - ((h / 60) % 2 - 1).abs());
final m = v - c;
final (r, g, b) = switch (h ~/ 60) {
0 => (c, x, 0.0),
1 => (x, c, 0.0),
2 => (0.0, c, x),
3 => (0.0, x, c),
4 => (x, 0.0, c),
_ => (c, 0.0, x),
};
int acht(double f) => ((f + m) * 255).round().clamp(0, 255);
return PosColor(acht(r), acht(g), acht(b));
}