PlotDirector/PlotLine/Services/PlotLineColours.cs
Nick Beckley e48889ac05 Complete desktop workspaces, context menus and plot health
Commit the pending application, help and browser regression work. Pin the patched PKCS dependency for the production release.
2026-10-31 09:27:04 +00:00

25 lines
1.0 KiB
C#

namespace PlotLine.Services;
/// <summary>Stable defaults for older lines which all inherited the original green.</summary>
public static class PlotLineColours
{
public static string ForLine(int plotLineId, string? colour)
{
if (!string.IsNullOrWhiteSpace(colour) && !colour.Equals("#2f6f63", StringComparison.OrdinalIgnoreCase)) return colour;
// Identity, never selection order, determines the default. Explicit choices are preserved.
var hue = ((uint)plotLineId * 137.508) % 360 / 60;
const double chroma = .48;
var secondary = chroma * (1 - Math.Abs(hue % 2 - 1));
var (r, g, b) = hue switch
{
< 1 => (chroma, secondary, 0d),
< 2 => (secondary, chroma, 0d),
< 3 => (0d, chroma, secondary),
< 4 => (0d, secondary, chroma),
< 5 => (secondary, 0d, chroma),
_ => (chroma, 0d, secondary)
};
return $"#{(int)((r + .30) * 255):x2}{(int)((g + .30) * 255):x2}{(int)((b + .30) * 255):x2}";
}
}