feat(ui): replace random part colors with curated palette
Avoids visual confusion with reserved UI colors (orange preview parts, green/blue selection windows) by using a fixed 12-color palette that skips those hue zones. Removes unused HSLColor and RandomColorGenerator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,22 @@ namespace OpenNest
|
||||
private Color edgeSpacingColor;
|
||||
private Color previewPartColor;
|
||||
|
||||
public static readonly Color[] PartColors = new Color[]
|
||||
{
|
||||
Color.FromArgb(205, 92, 92), // Indian Red
|
||||
Color.FromArgb(148, 103, 189), // Medium Purple
|
||||
Color.FromArgb(75, 180, 175), // Teal
|
||||
Color.FromArgb(210, 190, 75), // Goldenrod
|
||||
Color.FromArgb(190, 85, 175), // Orchid
|
||||
Color.FromArgb(185, 115, 85), // Sienna
|
||||
Color.FromArgb(120, 100, 190), // Slate Blue
|
||||
Color.FromArgb(200, 100, 140), // Rose
|
||||
Color.FromArgb(80, 175, 155), // Sea Green
|
||||
Color.FromArgb(195, 160, 85), // Dark Khaki
|
||||
Color.FromArgb(175, 95, 160), // Plum
|
||||
Color.FromArgb(215, 130, 130), // Light Coral
|
||||
};
|
||||
|
||||
public static readonly ColorScheme Default = new ColorScheme
|
||||
{
|
||||
BackgroundColor = Color.DarkGray,
|
||||
|
||||
@@ -82,17 +82,13 @@ namespace OpenNest.Forms
|
||||
checkedListBox3.Items.Add(lineType, false);
|
||||
}
|
||||
|
||||
private static int colorIndex;
|
||||
|
||||
private static Color GetNextColor()
|
||||
{
|
||||
//if (colorIndex >= Colors.Length)
|
||||
// colorIndex = 0;
|
||||
|
||||
//var color = Colors[colorIndex];
|
||||
|
||||
//colorIndex++;
|
||||
|
||||
return new HSLColor(new Random().NextDouble() * 240, 240, 160);
|
||||
|
||||
var color = ColorScheme.PartColors[colorIndex % ColorScheme.PartColors.Length];
|
||||
colorIndex++;
|
||||
return color;
|
||||
}
|
||||
|
||||
public List<Drawing> GetDrawings()
|
||||
@@ -331,157 +327,4 @@ namespace OpenNest.Forms
|
||||
public override int GetHashCode() => Argb;
|
||||
}
|
||||
|
||||
public class RandomColorGenerator
|
||||
{
|
||||
private readonly Random random;
|
||||
|
||||
public RandomColorGenerator()
|
||||
{
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public Color GetNext()
|
||||
{
|
||||
var r = random.Next(255);
|
||||
Thread.Sleep(20);
|
||||
var g = random.Next(255);
|
||||
Thread.Sleep(20);
|
||||
var b = random.Next(255);
|
||||
|
||||
return Color.FromArgb(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
public class HSLColor
|
||||
{
|
||||
// Private data members below are on scale 0-1
|
||||
// They are scaled for use externally based on scale
|
||||
private double hue = 1.0;
|
||||
private double saturation = 1.0;
|
||||
private double luminosity = 1.0;
|
||||
|
||||
private const double scale = 240.0;
|
||||
|
||||
public double Hue
|
||||
{
|
||||
get { return hue * scale; }
|
||||
set { hue = CheckRange(value / scale); }
|
||||
}
|
||||
public double Saturation
|
||||
{
|
||||
get { return saturation * scale; }
|
||||
set { saturation = CheckRange(value / scale); }
|
||||
}
|
||||
public double Luminosity
|
||||
{
|
||||
get { return luminosity * scale; }
|
||||
set { luminosity = CheckRange(value / scale); }
|
||||
}
|
||||
|
||||
private double CheckRange(double value)
|
||||
{
|
||||
if (value < 0.0)
|
||||
value = 0.0;
|
||||
else if (value > 1.0)
|
||||
value = 1.0;
|
||||
return value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("H: {0:#0.##} S: {1:#0.##} L: {2:#0.##}", Hue, Saturation, Luminosity);
|
||||
}
|
||||
|
||||
public string ToRGBString()
|
||||
{
|
||||
Color color = (Color)this;
|
||||
return String.Format("R: {0:#0.##} G: {1:#0.##} B: {2:#0.##}", color.R, color.G, color.B);
|
||||
}
|
||||
|
||||
#region Casts to/from System.Drawing.Color
|
||||
public static implicit operator Color(HSLColor hslColor)
|
||||
{
|
||||
double r = 0, g = 0, b = 0;
|
||||
if (hslColor.luminosity != 0)
|
||||
{
|
||||
if (hslColor.saturation == 0)
|
||||
r = g = b = hslColor.luminosity;
|
||||
else
|
||||
{
|
||||
double temp2 = GetTemp2(hslColor);
|
||||
double temp1 = 2.0 * hslColor.luminosity - temp2;
|
||||
|
||||
r = GetColorComponent(temp1, temp2, hslColor.hue + 1.0 / 3.0);
|
||||
g = GetColorComponent(temp1, temp2, hslColor.hue);
|
||||
b = GetColorComponent(temp1, temp2, hslColor.hue - 1.0 / 3.0);
|
||||
}
|
||||
}
|
||||
return Color.FromArgb((int)(255 * r), (int)(255 * g), (int)(255 * b));
|
||||
}
|
||||
|
||||
private static double GetColorComponent(double temp1, double temp2, double temp3)
|
||||
{
|
||||
temp3 = MoveIntoRange(temp3);
|
||||
if (temp3 < 1.0 / 6.0)
|
||||
return temp1 + (temp2 - temp1) * 6.0 * temp3;
|
||||
else if (temp3 < 0.5)
|
||||
return temp2;
|
||||
else if (temp3 < 2.0 / 3.0)
|
||||
return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0);
|
||||
else
|
||||
return temp1;
|
||||
}
|
||||
private static double MoveIntoRange(double temp3)
|
||||
{
|
||||
if (temp3 < 0.0)
|
||||
temp3 += 1.0;
|
||||
else if (temp3 > 1.0)
|
||||
temp3 -= 1.0;
|
||||
return temp3;
|
||||
}
|
||||
private static double GetTemp2(HSLColor hslColor)
|
||||
{
|
||||
double temp2;
|
||||
if (hslColor.luminosity < 0.5) //<=??
|
||||
temp2 = hslColor.luminosity * (1.0 + hslColor.saturation);
|
||||
else
|
||||
temp2 = hslColor.luminosity + hslColor.saturation - (hslColor.luminosity * hslColor.saturation);
|
||||
return temp2;
|
||||
}
|
||||
|
||||
public static implicit operator HSLColor(Color color)
|
||||
{
|
||||
HSLColor hslColor = new HSLColor();
|
||||
hslColor.hue = color.GetHue() / 360.0; // we store hue as 0-1 as opposed to 0-360
|
||||
hslColor.luminosity = color.GetBrightness();
|
||||
hslColor.saturation = color.GetSaturation();
|
||||
return hslColor;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void SetRGB(int red, int green, int blue)
|
||||
{
|
||||
HSLColor hslColor = (HSLColor)Color.FromArgb(red, green, blue);
|
||||
this.hue = hslColor.hue;
|
||||
this.saturation = hslColor.saturation;
|
||||
this.luminosity = hslColor.luminosity;
|
||||
}
|
||||
|
||||
public HSLColor() { }
|
||||
public HSLColor(Color color)
|
||||
{
|
||||
SetRGB(color.R, color.G, color.B);
|
||||
}
|
||||
public HSLColor(int red, int green, int blue)
|
||||
{
|
||||
SetRGB(red, green, blue);
|
||||
}
|
||||
public HSLColor(double hue, double saturation, double luminosity)
|
||||
{
|
||||
this.Hue = hue;
|
||||
this.Saturation = saturation;
|
||||
this.Luminosity = luminosity;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user