Files
@ abff9027c612
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Models/PaintColor.cs - annotation
abff9027c612
2.8 KiB
text/x-csharp
Make the download URL a link in the README.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 8da5f6699d57 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using System;
namespace DesertPaintCodex.Models
{
public class PaintColor
{
private const byte LightTextValueCutoff = 150;
private const float RedIntensity = 0.299f;
private const float GreenIntensity = 0.587f;
private const float BlueIntensity = 0.114f;
public byte Red { get; set; }
public byte Blue { get; set; }
public byte Green { get; set; }
public string Name { get; private set; }
public bool UseWhiteText => Red * RedIntensity + Green * GreenIntensity + Blue * BlueIntensity < LightTextValueCutoff;
public PaintColor()
{
Name = "Undefined";
Red = 0;
Green = 0;
Blue = 0;
}
public PaintColor(string name, string hexRed, string hexGreen, string hexBlue)
{
Name = name;
Red = byte.Parse(hexRed, System.Globalization.NumberStyles.AllowHexSpecifier);
Green = byte.Parse(hexGreen, System.Globalization.NumberStyles.AllowHexSpecifier);
Blue = byte.Parse(hexBlue, System.Globalization.NumberStyles.AllowHexSpecifier);
}
public PaintColor(byte red, byte green, byte blue)
{
Name = "Undefined";
Red = red;
Green = green;
Blue = blue;
}
public PaintColor(PaintColor other)
{
Name = other.Name;
Red = other.Red;
Green = other.Green;
Blue = other.Blue;
}
public PaintColor(string name, PaintColor other)
{
Name = name;
Red = other.Red;
Green = other.Green;
Blue = other.Blue;
}
public void Set(string name, PaintColor other)
{
Name = name;
Red = other.Red;
Green = other.Green;
Blue = other.Blue;
}
public int GetDistanceSquared(PaintColor otherColor)
{
return (int)(Math.Pow(Red - otherColor.Red, 2) +
Math.Pow(Green - otherColor.Green, 2) +
Math.Pow(Blue - otherColor.Blue, 2));
}
public void Clear()
{
Red = 0;
Green = 0;
Blue = 0;
}
public void Set(PaintColor other)
{
Red = other.Red;
Green = other.Green;
Blue = other.Blue;
Name = other.Name;
}
public string ToHexString()
{
return "#" + Red.ToString("X2") + Green.ToString("X2") + Blue.ToString("X2");
}
public override string ToString()
{
return "[" + Name + ", " + Red + ", " + Green + ", " + Blue + "]";
}
}
}
|