public double SumOfDistances(ColorRGBAf other) { double dist = Math.Abs(red - other.red) + Math.Abs(green - other.green) + Math.Abs(blue - other.blue); return dist; }
public static ColorRGBAf GetTweenColor(ColorRGBAf c1, ColorRGBAf c2, float ratioOf2) { if (ratioOf2 <= 0) { return new ColorRGBAf(c1); } if (ratioOf2 >= 1.0) { return new ColorRGBAf(c2); } // figure out how much of each color we should be. double ratioOf1 = 1.0 - ratioOf2; return new ColorRGBAf( c1.red * ratioOf1 + c2.red * ratioOf2, c1.green * ratioOf1 + c2.green * ratioOf2, c1.blue * ratioOf1 + c2.blue * ratioOf2); }
public ColorRGBAf Blend(ColorRGBAf other, double weight) { ColorRGBAf result = new ColorRGBAf(this); result = this * (1 - weight) + other * weight; return result; }
public static ColorRGBAf rgba_pre(ColorRGBAf c) { return new ColorRGBAf(c).premultiply(); }
public static ColorRGBAf rgba_pre(ColorRGBAf c, float a) { return new ColorRGBAf(c, a).premultiply(); }
static public ColorRGBAf operator *(ColorRGBAf A, double doubleB) { float B = (float)doubleB; ColorRGBAf temp = new ColorRGBAf(); temp.red = A.red * B; temp.green = A.green * B; temp.blue = A.blue * B; temp.alpha = A.alpha * B; return temp; }
public static ColorRGBAf FromWaveLength(float wl, float gamma) { ColorRGBAf t = new ColorRGBAf(0.0f, 0.0f, 0.0f); if (wl >= 380.0 && wl <= 440.0) { t.red = (float)(-1.0 * (wl - 440.0) / (440.0 - 380.0)); t.blue = 1.0f; } else if (wl >= 440.0 && wl <= 490.0) { t.green = (float)((wl - 440.0) / (490.0 - 440.0)); t.blue = 1.0f; } else if (wl >= 490.0 && wl <= 510.0) { t.green = 1.0f; t.blue = (float)(-1.0 * (wl - 510.0) / (510.0 - 490.0)); } else if (wl >= 510.0 && wl <= 580.0) { t.red = (float)((wl - 510.0) / (580.0 - 510.0)); t.green = 1.0f; } else if (wl >= 580.0 && wl <= 645.0) { t.red = 1.0f; t.green = (float)(-1.0 * (wl - 645.0) / (645.0 - 580.0)); } else if (wl >= 645.0 && wl <= 780.0) { t.red = 1.0f; } float s = 1.0f; if (wl > 700.0) s = (float)(0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0)); else if (wl < 420.0) s = (float)(0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0)); t.red = (float)Math.Pow(t.red * s, gamma); t.green = (float)Math.Pow(t.green * s, gamma); t.blue = (float)Math.Pow(t.blue * s, gamma); return t; }
static public ColorRGBAf operator /(ColorRGBAf A, float B) { ColorRGBAf temp = new ColorRGBAf(); temp.red = A.red / B; temp.green = A.green / B; temp.blue = A.blue / B; temp.alpha = A.alpha / B; return temp; }
static public ColorRGBAf operator /(ColorRGBAf A, ColorRGBAf B) { ColorRGBAf temp = new ColorRGBAf(); temp.red = A.red / B.red; temp.green = A.green / B.green; temp.blue = A.blue / B.blue; temp.alpha = A.alpha / B.alpha; return temp; }
public static ColorRGBAf AdjustLightness(ColorRGBAf original, double lightnessMultiplier) { double hue0To1; double saturation0To1; double lightness0To1; original.GetHSL(out hue0To1, out saturation0To1, out lightness0To1); lightness0To1 *= lightnessMultiplier; return FromHSL(hue0To1, saturation0To1, lightness0To1); }
public ColorRGBAf(ColorRGBAf c, float a_) { red = c.red; green = c.green; blue = c.blue; alpha = a_; }
public ColorRGBAf(ColorRGBAf c) : this(c, c.alpha) { }