private void Page_Loaded(object sender, RoutedEventArgs e) { AddRandomPoint(); AddRandomPoint(); AddRandomPoint(); // these are functions that sets different properties of drawn ellipses; // these functions can be replaced by real, non-demo ones. chart.AddPropertyBindingForNamedPart<Point>("ellipse", Ellipse.FillProperty, p => { double hue = Math.Sin(1000 * (p.X + p.Y)) * 180 + 180; var color = new HsbColor(hue, 0.2, 1); return new SolidColorBrush(color.ToArgbColor()).MakeTransparent(0.7); }); chart.AddPropertyBindingForNamedPart<Point>("ellipse", Ellipse.StrokeProperty, p => { double hue = Math.Sin(1000 * (p.X + p.Y)) * 180 + 180; var color = new HsbColor(hue, 1, 1); return new SolidColorBrush(color.ToArgbColor()); }); chart.AddPropertyBindingForNamedPart<Point>("ellipse", Ellipse.RenderTransformProperty, p => new RotateTransform(120 * Math.Atan2(p.Y, p.X))); chart.AddPropertyBinding<Point>(ViewportPanel.ViewportWidthProperty, p => 0.2 * Math.Abs(Math.Sin(p.X))); chart.AddPropertyBinding<Point>(ViewportPanel.ViewportHeightProperty, p => 0.2 * Math.Abs(Math.Cos(p.X))); DataContext = points; }
/// <summary> /// Creates color from HSB color space with random hue and saturation and brighness equal to 1. /// </summary> /// <returns></returns> public static Color CreateColorWithRandomHue() { double hue = random.NextDouble() * 360; HsbColor hsbColor = new HsbColor(hue, 1, 1); return(hsbColor.ToArgbColor()); }
public static SolidColorBrush ChangeLightness(this SolidColorBrush brush, double lightnessFactor) { Color color = brush.Color; HsbColor hsbColor = HsbColor.FromArgbColor(color); hsbColor.Brightness *= lightnessFactor; if (hsbColor.Brightness > 1.0) { hsbColor.Brightness = 1.0; } SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor()); return(result); }
public static SolidColorBrush ChangeSaturation(this SolidColorBrush brush, double saturationFactor) { Color color = brush.Color; HsbColor hsbColor = HsbColor.FromArgbColor(color); hsbColor.Saturation *= saturationFactor; if (hsbColor.Saturation > 1.0) { hsbColor.Saturation = 1.0; } SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor()); return(result); }
/// <summary> /// Creates color from HSB color space with random hue and saturation and brighness equal to 1. /// </summary> /// <returns></returns> public static Color CreateColorWithRandomHue() { double hue = random.NextDouble() * 360; HsbColor hsbColor = new HsbColor(hue, 1, 1); return hsbColor.ToArgbColor(); }