public static XColor Parse(string p) { XColor res = new XColor(0, 0, 0, 255); int i = 0; for(int c=0;c<4;++c) { int start = i; while (i < p.Length && !IsDelim(p[i])) ++i; byte val = 0; if (!byte.TryParse(p.Substring(start, i - start), out val)) { val = c < 3 ? (byte)0 : (byte)255; } switch (c) { case 0: res.R = val; break; case 1: res.G = val; break; case 2: res.B = val; break; case 3: res.A = val; break; } while (i < p.Length && IsDelim(p[i])) ++i; } return res; }
public static XColor Lerp(XColor c1, XColor c2, float lerp) { return new XColor( (byte)(c1.R + (c2.R - c1.R) * lerp), (byte)(c1.G + (c2.G - c1.G) * lerp), (byte)(c1.B + (c2.B - c1.B) * lerp), (byte)(c1.A + (c2.A - c1.A) * lerp) ); }