public double ToSaturation( ) { AHSB hsb = this.ToAHSB(); return(hsb.Brightness == 0 ? m_saturation : hsb.Saturation); }
public static Color GetPure( this Color c ) { AHSB ahsb = c.Double().ToAHSB(); ahsb.Brightness = 1.0; ahsb.Saturation = 1.0; return(ahsb.Double().ToColor()); }
public static DoubleColor Double( this AHSB ahsb ) { double a = ahsb.Alpha; double hue = ahsb.HueDegree; double saturation = ahsb.Saturation; double value = ahsb.Brightness; DoubleColor ret; int hi = ((int)(hue / 60)) % 6; double f = hue / 60 - (int)(hue / 60); value = value * 255; double v = value; double p = (value * (1 - saturation)); double q = (value * (1 - f * saturation)); double t = (value * (1 - (1 - f) * saturation)); if (hi == 0) { ret = new DoubleColor(a * 255, v, t, p); } else if (hi == 1) { ret = new DoubleColor(a * 255, q, v, p); } else if (hi == 2) { ret = new DoubleColor(a * 255, p, v, t); } else if (hi == 3) { ret = new DoubleColor(a * 255, p, q, v); } else if (hi == 4) { ret = new DoubleColor(a * 255, t, p, v); } else { ret = new DoubleColor(a * 255, v, p, q); } ret.HueDegree = hue; ret.Saturation = saturation; return(ret); }
public static DoubleColor AlterHue( this DoubleColor c, ColorWheelBase wheel, double hue ) { AHSB src = c.ToAHSB(); AHSB dest = wheel.GetColor(hue).ToAHSB(); dest.Saturation = src.Saturation; dest.Brightness = src.Brightness; dest.Alpha = src.Alpha; return(dest.Double()); }
public static AHSB ToAHSB( this DoubleColor c ) { double a = c.A / 255.0; double r = c.R / 255.0; double g = c.G / 255.0; double b = c.B / 255.0; AHSB ret; double max = Math.Max(r, Math.Max(g, b)); double min = Math.Min(r, Math.Min(g, b)); // // Black - gray - white // if (min == max) { ret = new AHSB(a, 0, 0, (double)min); } else { var d = (r == min) ? g - b : ((b == min) ? r - g : b - r); var h = (r == min) ? 3 : ((b == min) ? 1 : 5); double hue = 60 * (h - d / (max - min)); double sat = (max - min) / max; double value = max; ret = new AHSB(a, hue, sat, value); } if (ret.Saturation == 0) { ret.HueDegree = c.HueDegree; } if (ret.Brightness == 0) { ret.Saturation = c.Saturation; } return(ret); }
protected virtual void UpdateHSBComponents( ) { AHSB p = m_previous.ToAHSB(); AHSB c = m_color.ToAHSB(); if (p.HueDegree != c.HueDegree) { FirePropertyChanged("Hue360"); } if (p.Saturation255 != c.Saturation255) { FirePropertyChanged("Saturation255"); } if (p.Brightness255 != c.Brightness255) { FirePropertyChanged("Brightness255"); } }
public static AHSB Alter( this AHSB hsb, double?hue = null, double?saturation = null, double?brightness = null ) { if (hue != null) { hsb.HueDegree = hue.Value; } if (saturation != null) { hsb.Saturation = saturation.Value; } if (brightness != null) { hsb.Brightness = brightness.Value; } return(hsb); }
public void UpdateBaseAngle( double value ) { double hue = value; double comp = 0.0; double hue1 = 0.0; double hue2 = 0.0; double hue3 = 0.0; if (m_wheel != null) { value = m_wheel.FixAngle(value); hue = m_wheel.GetColor(value).ToAHSB().HueDegree; } switch (m_schema) { case PaletteSchemaType.Monochromatic: for (int i = 0; i < m_colors.Count; ++i) { AHSB hsb = m_colors[i].Color; hsb.HueDegree = hue; m_colors[i].Color = hsb; } break; case PaletteSchemaType.Complementary: case PaletteSchemaType.Analogous: for (int i = 0; i < m_colors.Count; ++i) { AHSB hsb = m_colors[i].Color; hsb.HueDegree = m_colors[i].VectorIndex == 0 ? hue : m_wheel.GetColor(value + m_angle).ToAHSB().HueDegree; m_colors[i].Color = hsb; } break; case PaletteSchemaType.SplitComplementary: comp = 180; goto case PaletteSchemaType.SplitAnalogous; case PaletteSchemaType.Triad: case PaletteSchemaType.SplitAnalogous: if (m_wheel != null) { hue1 = m_wheel.GetColor(value + comp + m_angle).ToAHSB().HueDegree; hue2 = m_wheel.GetColor(value + comp - m_angle).ToAHSB().HueDegree; } for (int i = 0; i < m_colors.Count; ++i) { AHSB hsb = m_colors[i].Color; int idx = m_colors[i].VectorIndex; hsb.HueDegree = idx % 3 == 0 ? hue : (idx % 3 == 1 ? hue1 : hue2); m_colors[i].Color = hsb; } break; case PaletteSchemaType.Quadrants: hue1 = m_wheel.GetColor(value + 90).ToAHSB().HueDegree; hue2 = m_wheel.GetColor(value + 180).ToAHSB().HueDegree; hue3 = m_wheel.GetColor(value + 270).ToAHSB().HueDegree; for (int i = 0; i < m_colors.Count; ++i) { AHSB hsb = m_colors[i].Color; int idx = m_colors[i].VectorIndex; hsb.HueDegree = idx % 4 == 0 ? hue : (idx % 4 == 1 ? hue1 : (idx % 4 == 2 ? hue2 : hue3)); m_colors[i].Color = hsb; } break; case PaletteSchemaType.Tetrads: hue1 = m_wheel.GetColor(value + m_angle).ToAHSB().HueDegree; hue2 = m_wheel.GetColor(value + 180).ToAHSB().HueDegree; hue3 = m_wheel.GetColor(value + 180.0 + m_angle).ToAHSB().HueDegree; for (int i = 0; i < m_colors.Count; ++i) { AHSB hsb = m_colors[i].Color; int idx = m_colors[i].VectorIndex; hsb.HueDegree = idx % 4 == 0 ? hue : (idx % 4 == 1 ? hue1 : (idx % 4 == 2 ? hue2 : hue3)); m_colors[i].Color = hsb; } break; } }
/// /// <summary> /// Generate palette by base color, schema and number of colors. /// Number of colors should be more than 1</summary> /// public static Palette Create( ColorWheelBase wheel, Color baseColor, PaletteSchemaType schema = PaletteSchemaType.Complementary, int colorCount = 5, double fromSat = 1.0, double toSat = 0.2, double fromBri = 0.2, double toBri = 0.9 ) { double angle = 30; double baseAngle = 0; double alpha = baseColor.A / 255.0; double incs = 0; double incb = 0; AHSB c; int index = 0; wheel = wheel ?? new RGBColorWheel(); baseAngle = wheel.GetAngle(baseColor.Double()); if (schema == PaletteSchemaType.Complementary) { angle = 180.0; } else if (schema == PaletteSchemaType.Quadrants) { angle = 90.0; } else if (schema == PaletteSchemaType.Triad) { angle = 120.0; } Palette p = new Palette(wheel) { Schema = schema, Angle = angle }; if (colorCount > 1) { incs = (toSat - fromSat) / (colorCount - 1); incb = (toBri - fromBri) / (colorCount - 1); } for (int i = 0; i < colorCount; ++i) { switch (p.Schema) { case PaletteSchemaType.Monochromatic: break; case PaletteSchemaType.Quadrants: case PaletteSchemaType.Tetrads: index = i % 4; break; case PaletteSchemaType.Custom: case PaletteSchemaType.SplitComplementary: case PaletteSchemaType.SplitAnalogous: case PaletteSchemaType.Triad: index = i % 3; break; case PaletteSchemaType.Complementary: case PaletteSchemaType.Analogous: index = i % 2; break; default: throw new ArgumentException(); } c = new AHSB(alpha, baseAngle, fromSat, fromBri); fromSat = AHSB.Fix(fromSat + incs); fromBri = AHSB.Fix(fromBri + incb); p.Colors.Add(new PaletteColor() { Name = i.ToString(), VectorIndex = index, Color = c }); } p.BaseAngle = baseAngle; return(p); }
public abstract double GetAngle( AHSB c );
public override double GetAngle( AHSB c ) { return(ToWheelAngle(c.HueDegree)); }
public override double GetAngle( AHSB c ) { return(c.HueDegree); }
public static DoubleColor FromAHSB( AHSB a ) { return(a.Double()); }