private static GradientStopCollection fromInterpolation(GradientStopCollection min, double p, GradientStopCollection max) { if (min.Count < max.Count) { GradientStopCollection t = min; min = max; max = t; p = 1 - p; } GradientStopCollection ret = new GradientStopCollection(); for (int i = 0; i < min.Count; ++i) { ret.Add(new GradientStop() { Color = ColorTool.FromARGBInterpolation(min[i].Color, p, max[i].Color), Offset = min[i].Offset * (1.0 - p) + max[i].Offset * p }); } for (int i = min.Count; i < max.Count; ++i) { ret.Add(new GradientStop() { Color = ColorTool.FromARGBInterpolation(min[min.Count - 1].Color, p, max[i].Color), Offset = min[min.Count - 1].Offset * (1.0 - p) + max[i].Offset * p }); } return(ret); }
private void CalcTabStops() { _gradStops.Clear(); if (Value > 0) { double dLineValue = (1 - Value / MaxValue) / 2; if (dLineValue > 0.49) { dLineValue = 0.49; } _gradStops.Add(new GradientStop(Colors.Transparent, 0.500)); _gradStops.Add(new GradientStop(Colors.Transparent, 1.0)); _gradStops.Add(new GradientStop(FillColor, 0.499)); _gradStops.Add(new GradientStop(Colors.Transparent, dLineValue)); _gradStops.Add(new GradientStop(FillColor, dLineValue + 0.001)); } else { double dLineValue = 0.5 + (Value / MinValue / 2); if (dLineValue >= 1) { dLineValue = 0.998; } if (dLineValue == 0.5) { dLineValue = 0.5001; } _gradStops.Add(new GradientStop(Colors.Transparent, dLineValue + 0.01)); _gradStops.Add(new GradientStop(Colors.Transparent, 1.0)); _gradStops.Add(new GradientStop(FillColor, dLineValue)); _gradStops.Add(new GradientStop(Colors.Transparent, 0.5)); _gradStops.Add(new GradientStop(FillColor, 0.501)); } this.InvalidateVisual(); }
internal CurvyTabVisual(FrameworkElement parentVisual) { this.parentVisual = parentVisual; this.TabWidth = 176.0; GradientStopCollection inactiveStops = new GradientStopCollection(); inactiveStops.Add(new GradientStop(Color.FromRgb(210, 222, 234), 0.0)); inactiveStops.Add(new GradientStop(Color.FromRgb(190, 201, 214), 1.0)); inactiveBrush = new LinearGradientBrush(inactiveStops, 90); GradientStopCollection activeStops = new GradientStopCollection(); activeStops.Add(new GradientStop(Color.FromRgb(255, 255, 255), 0.0)); activeStops.Add(new GradientStop(Color.FromRgb(224, 224, 224), 1.0)); activeBrush = new LinearGradientBrush(activeStops, 90); // GradientStopCollection backgroundStops = new GradientStopCollection(); // backgroundStops.Add(new GradientStop(Color.FromRgb(127, 127, 127), 0.0)); // backgroundStops.Add(new GradientStop(Color.FromRgb(160, 160, 160), 0.2)); // backgroundStops.Add(new GradientStop(Color.FromRgb(224, 224, 224), 1.0)); // backgroundBrush = new LinearGradientBrush(backgroundStops, 90); borderLine = new Pen(new SolidColorBrush(Color.FromRgb(224, 224, 224)), 2); }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { Pen pen = new Pen(new SolidColorBrush(Colors.Black), 1); if (LightOn) { GradientStopCollection stopC2 = new GradientStopCollection(); stopC2.Add(new GradientStop(Colors.White, 0)); stopC2.Add(new GradientStop(Colors.Red, 1)); RadialGradientBrush r2 = new RadialGradientBrush(stopC2); r2.RadiusX = 1; r2.RadiusY = 1; r2.GradientOrigin = new Point(0.7, 0.3); drawingContext.DrawEllipse(r2, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2); } else { GradientStopCollection stopC1 = new GradientStopCollection(); stopC1.Add(new GradientStop(Colors.White, 0)); stopC1.Add(new GradientStop(Colors.LightGreen, 1)); RadialGradientBrush r1 = new RadialGradientBrush(stopC1); r1.RadiusX = 1; r1.RadiusY = 1; r1.GradientOrigin = new Point(0.7, 0.3); drawingContext.DrawEllipse(r1, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var original = (double)value; var gradientStopCollection = new GradientStopCollection(); if (original == 1) { gradientStopCollection.Add(new GradientStop(Colors.Red, 0)); gradientStopCollection.Add(new GradientStop(Colors.Red, 1)); } else { for (double v = 0; v < original; v += 0.01) { gradientStopCollection.Add(new GradientStop(Utils.DoubleToColor(v), v)); } } var brush = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(1, 0) }; brush.GradientStops = gradientStopCollection; return(brush); }
public BGBarListBoxItem(RecFolderInfo item) { InitializeComponent(); labelFolder.Content = item.recFolder; progressBar.Value = item.freeBytes; progressBar.Maximum = item.totalBytes; GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop(Colors.Red, 0.1)); stops.Add(new GradientStop(Colors.Yellow, 0.3)); stops.Add(new GradientStop(Colors.Lime, 0.4)); LinearGradientBrush brush = new LinearGradientBrush(stops, new Point(0, 0), new Point(1, 0)); brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; progressBar.Background = brush; if (item.freeBytes > 0 && item.totalBytes > 0) { List <string> units = new List <string> { "Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" }; int unit_base = 1024; int n = (int)Math.Floor(Math.Min(Math.Log(item.freeBytes) / Math.Log(unit_base), units.Count - 1)); int m = (int)Math.Floor(Math.Min(Math.Log(item.totalBytes) / Math.Log(unit_base), units.Count - 1)); ToolTip = "空き容量: " + Math.Round(item.freeBytes / Math.Pow(unit_base, n), 1).ToString() + " " + units[n] + "/" + Math.Round(item.totalBytes / Math.Pow(unit_base, m), 1).ToString() + " " + units[m]; } }
/// <summary> /// Initializes a new instance of the <see cref="HeatMapLayer"/> class. /// </summary> public HeatMapLayer() { GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop() { Color = Colors.Transparent, Offset = 0 }); stops.Add(new GradientStop() { Color = Colors.Blue, Offset = .5 }); stops.Add(new GradientStop() { Color = Colors.Red, Offset = .75 }); stops.Add(new GradientStop() { Color = Colors.Yellow, Offset = .8 }); stops.Add(new GradientStop() { Color = Colors.White, Offset = 1 }); Gradient = stops; HeatMapPoints = new ESRI.ArcGIS.Client.Geometry.PointCollection(); //Create a separate thread for rendering the heatmap layer. renderThread = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; renderThread.ProgressChanged += new ProgressChangedEventHandler(renderThread_ProgressChanged); renderThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(renderThread_RunWorkerCompleted); renderThread.DoWork += new DoWorkEventHandler(renderThread_DoWork); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { LinearGradientBrush linearGradientBrush = (LinearGradientBrush)null; ColorModel source = value as ColorModel; if (source != null) { ColorModel colorModel = new ColorModel(source); colorModel.ScA = 1f; colorModel.HlsS = 1f; colorModel.HlsL = 0.5f; GradientStop gradientStop1 = new GradientStop(Colors.Black, 0.0); gradientStop1.Freeze(); GradientStop gradientStop2 = new GradientStop(colorModel.Color, 0.5); gradientStop2.Freeze(); GradientStop gradientStop3 = new GradientStop(Colors.White, 1.0); gradientStop3.Freeze(); GradientStopCollection gradientStopCollection = new GradientStopCollection(3); gradientStopCollection.Add(gradientStop1); gradientStopCollection.Add(gradientStop2); gradientStopCollection.Add(gradientStop3); gradientStopCollection.Freeze(); linearGradientBrush = new LinearGradientBrush(); linearGradientBrush.StartPoint = new Point(0.0, 0.0); linearGradientBrush.EndPoint = new Point(1.0, 0.0); linearGradientBrush.GradientStops = gradientStopCollection; linearGradientBrush.Freeze(); } return((object)linearGradientBrush); }
private Rectangle CreateRectangler(int column) { var rect = new Rectangle(); if (column > 0) { rect.SetValue(Grid.ColumnSpanProperty, column); } rect.SetValue(Canvas.ZIndexProperty, -1); rect.SetValue(Grid.RowProperty, 0); var colls = new GradientStopCollection(); var stop1 = new GradientStop(); stop1.Color = Color.FromArgb(0xff, 0xe9, 0xed, 0xf0); stop1.Offset = 0; var stop2 = new GradientStop(); stop2.Color = Color.FromArgb(0xff, 0xff, 0xff, 0xff); stop2.Offset = 1; colls.Add(stop1); colls.Add(stop2); var linebrush = new LinearGradientBrush(colls, 0); linebrush.StartPoint = new Point(0, 0); linebrush.EndPoint = new Point(0, 1); rect.Fill = linebrush; return(rect); }
public ColorEditViewModel() { GradientStopCollection gradientStops1 = new GradientStopCollection(); gradientStops1.Add(new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("#FFADF5F5"), Offset = 1 }); gradientStops1.Add(new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("#FFECADF5"), Offset = 0 }); brush3 = new LinearGradientBrush(gradientStops1, new Point(0.5, 0), new Point(0.5, 1)); GradientStopCollection gradientStops2 = new GradientStopCollection(); gradientStops2.Add(new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("#FF324243"), Offset = 0.999444444444443 }); gradientStops2.Add(new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("#FF24C7EA"), Offset = 0.0127777777777768 }); brush4 = new RadialGradientBrush() { GradientStops = gradientStops2, GradientOrigin = new Point(0.5, 0.5), Center = new Point(0.5, 0.5) }; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double gradientSize = System.Convert.ToDouble(parameter); double boundsSize = System.Convert.ToDouble(values[0]); double maskSize = System.Convert.ToDouble(values[1]); var maskVisibility = values.Length == 3 ? (Visibility)values[2] : Visibility.Visible; maskSize = MathEx.Clamp(maskSize, 0, maskVisibility == Visibility.Visible ? boundsSize : 0); double transparentSize = boundsSize - maskSize; double maskRatio = maskSize / boundsSize; gradientSize = MathEx.Clamp(gradientSize, 0, transparentSize / 2); double gradientRatio = transparentSize > 0 ? gradientSize / transparentSize : 0; var gradientStopCollection = new GradientStopCollection(); if (LeftTopMask) { gradientStopCollection.Add(new GradientStop(Colors.White, maskRatio)); gradientStopCollection.Add(new GradientStop(Colors.Transparent, maskRatio + gradientRatio)); } else { gradientStopCollection.Add(new GradientStop(Colors.Transparent, 1 - maskRatio - gradientRatio)); gradientStopCollection.Add(new GradientStop(Colors.White, 1 - maskRatio)); } return(Orientation == Orientation.Horizontal ? new LinearGradientBrush(gradientStopCollection, new Point(0, 0), new Point(1, 0)) : new LinearGradientBrush(gradientStopCollection, new Point(0, 0), new Point(0, 1))); }
private void InitializeMap(IReadOnlyList <CountryInfoEx> info) { _geoMap.Source = _MapFile; _geoMap.AnimationsSpeed = new TimeSpan(1000000); _geoMap.Dock = DockStyle.Fill; _geoMap.DefaultLandFill = Brushes.Gray; _geoMap.EnableZoomingAndPanning = true; _geoMap.Hoverable = true; GradientStopCollection collection = new GradientStopCollection(); collection.Add(new GradientStop(Colors.MediumSeaGreen, 0.0)); collection.Add(new GradientStop(Colors.Gold, 0.5)); collection.Add(new GradientStop(Colors.Crimson, 1.0)); _geoMap.GradientStopCollection = collection; Dictionary <string, double> scaledValues = new Dictionary <string, double>(); foreach (CountryInfoEx country in info) { int active = country.Confirmed - country.Deaths - country.Recovered; double activeLog = (active > 0) ? Math.Log(active) : 0; scaledValues[country.CountryCode] = activeLog; } _geoMap.HeatMap = scaledValues; _geoMap.LandClick += OnUserClick; }
public BGBarListBoxItem(RecFolderInfo item) { InitializeComponent(); labelFolder.Content = item.recFolder; progressBar.Value = item.freeBytes; progressBar.Maximum = item.totalBytes; GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop(Colors.Red, 0.1)); stops.Add(new GradientStop(Colors.Yellow, 0.3)); stops.Add(new GradientStop(Colors.Lime, 0.4)); LinearGradientBrush brush = new LinearGradientBrush(stops, new Point(0, 0), new Point(1, 0)); brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; progressBar.Background = brush; if (item.freeBytes > 0 && item.totalBytes > 0) { List<string> units = new List<string> { "Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" }; int unit_base = 1024; int n = (int)Math.Floor(Math.Min(Math.Log(item.freeBytes) / Math.Log(unit_base), units.Count - 1)); int m = (int)Math.Floor(Math.Min(Math.Log(item.totalBytes) / Math.Log(unit_base), units.Count - 1)); ToolTip = "空き容量: " + Math.Round(item.freeBytes / Math.Pow(unit_base, n), 1).ToString() + " " + units[n] + "/" + Math.Round(item.totalBytes / Math.Pow(unit_base, m), 1).ToString() + " " + units[m]; } }
private void setContent() { Grid grid = new Grid() { Width = 48, Height = 48, Visibility = Visibility.Collapsed }; thumb = new Image() { Width = 48, Height = 48, Opacity = 0.7 }; GradientStopCollection gsc = new GradientStopCollection(); gsc.Add(new GradientStop(Colors.DeepSkyBlue, 0.0)); gsc.Add(new GradientStop(Colors.DodgerBlue, 0.5)); gsc.Add(new GradientStop(Colors.DeepSkyBlue, 1.0)); LinearGradientBrush lgb = new LinearGradientBrush(gsc, new Point(0.5, 0), new Point(0.5, 1)); borderCount = new Border() { Background = lgb, BorderThickness = new Thickness(1), BorderBrush = SolidColors.White, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom }; labelCount = new Label() { Margin = new Thickness(4, 1, 4, 1), Padding = new Thickness(0), FontSize = 10, FontWeight = FontWeights.SemiBold, Foreground = SolidColors.White, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; borderCount.Child = labelCount; grid.Children.Add(thumb); grid.Children.Add(borderCount); content = grid; }
public static Brush ErrorBrush() { GradientStopCollection colors = new GradientStopCollection(); GradientStop min = new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("Red"), Offset = 0, }; colors.Add(min); GradientStop max = new GradientStop() { Color = (Color)ColorConverter.ConvertFromString("White"), Offset = 1, }; colors.Add(max); LinearGradientBrush brush = new LinearGradientBrush(colors) { StartPoint = new Point(0.5, 0), EndPoint = new Point(0.5, 1), }; return(brush); }
private void Border_MouseMove(object sender, MouseEventArgs e) { Border border = sender as Border; double x = e.GetPosition(border).X / border.Width; double y = e.GetPosition(border).Y / border.Height; GradientStopCollection backgroundGradientStopCollection = new GradientStopCollection(); backgroundGradientStopCollection.Add(new GradientStop(Colors.White, -3)); backgroundGradientStopCollection.Add(new GradientStop((FindResource("EmeraldBrush") as SolidColorBrush).Color, 1)); RadialGradientBrush backgroundRadialGradientBrush = new RadialGradientBrush(backgroundGradientStopCollection); backgroundRadialGradientBrush.Center = new Point(x, y); backgroundRadialGradientBrush.GradientOrigin = new Point(x, y); GradientStopCollection borderGradientStopCollection = new GradientStopCollection(); borderGradientStopCollection.Add(new GradientStop(Colors.White, 0.38)); borderGradientStopCollection.Add(new GradientStop((FindResource("EmeraldBrush") as SolidColorBrush).Color, 0.62)); RadialGradientBrush borderRadialGradientBrush = new RadialGradientBrush(borderGradientStopCollection); borderRadialGradientBrush.Center = new Point(x, y); borderRadialGradientBrush.GradientOrigin = new Point(x, y); border.Background = backgroundRadialGradientBrush; border.BorderBrush = borderRadialGradientBrush; }
private void SetOpacityMask() { var gradientCollection = new GradientStopCollection(); var gradientStop1 = new GradientStop(Colors.Black, 0); var gradientStop2 = new GradientStop(Colors.Transparent, 1); gradientCollection.Add(gradientStop1); gradientCollection.Add(gradientStop2); Point StartPoint = new Point(); Point EndPoint = new Point(); if (IsHorizontal) { StartPoint.X = StartPercent; EndPoint.X = 1; } else { StartPoint.Y = StartPercent; EndPoint.Y = 1; } InitialOpacityMask = new LinearGradientBrush(gradientCollection, StartPoint, EndPoint); AssociatedObject.OpacityMask = InitialOpacityMask; }
private Brush GenerateBrush() { var gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop { Color = Windows.UI.Colors.Green, Offset = 0 }); gradientStops.Add(new GradientStop { Color = Windows.UI.Colors.Green, Offset = 0 }); gradientStops.Add(new GradientStop { Color = Windows.UI.Colors.Red, Offset = 0.25 }); gradientStops.Add(new GradientStop { Color = Windows.UI.Colors.Yellow, Offset = 0.75 }); gradientStops.Add(new GradientStop { Color = Windows.UI.Colors.LimeGreen, Offset = 1 }); var brush = new LinearGradientBrush(gradientStops, 0); brush.StartPoint = new Windows.Foundation.Point(0, 0); brush.EndPoint = new Windows.Foundation.Point(1, 0); return(brush); }
private void CreateGradientColorsArray() { // We use HeightMapMesh3D.GetGradientColorsArray to create an array with color values created from the gradient. The array size is 30. var gradientStopCollection = new GradientStopCollection(); //gradientStopCollection.Add(new GradientStop(Colors.Red, 1)); //gradientStopCollection.Add(new GradientStop(Colors.Yellow, 0.75)); //gradientStopCollection.Add(new GradientStop(Colors.Lime, 0.5)); //gradientStopCollection.Add(new GradientStop(Colors.Aqua, 0.25)); //gradientStopCollection.Add(new GradientStop(Colors.Blue, 0)); // We adjust the colors to create better heat effect gradientStopCollection.Add(new GradientStop(Colors.Red, 0)); gradientStopCollection.Add(new GradientStop(Colors.Red, 0.10)); gradientStopCollection.Add(new GradientStop(Colors.Yellow, 0.4)); gradientStopCollection.Add(new GradientStop(Colors.Aqua, 0.7)); gradientStopCollection.Add(new GradientStop(Colors.Aqua, 1)); var linearGradientBrush = new LinearGradientBrush(gradientStopCollection, new System.Windows.Point(0, 0), new System.Windows.Point(0, 1)); // We can use the GetGradientColorsArray from HeightMapMesh3D (Ab3d.PowerToys libraty) to convert the LinearGradientBrush to array of 30 colors var gradientColorsArray = Ab3d.Meshes.HeightMapMesh3D.GetGradientColorsArray(linearGradientBrush, 30); // Convert WPF colors to SharpDX Color4 _gradientColor4Array = new Color4[gradientColorsArray.Length]; for (var i = 0; i < gradientColorsArray.Length; i++) { _gradientColor4Array[i] = gradientColorsArray[i].ToColor4(); } }
public void Paint(MessageOwner sender) { GradientStopCollection gradientStops = new GradientStopCollection(); GradientStop gradientStop1 = null, gradientStop2 = null; switch (sender) { case MessageOwner.SERVER: Color color = (Color)ColorConverter.ConvertFromString("#FF051BF7"); gradientStop1 = new GradientStop(color, 0); color = (Color)ColorConverter.ConvertFromString("#FF08D1F8"); gradientStop2 = new GradientStop(color, 2); break; case MessageOwner.YOU: color = (Color)ColorConverter.ConvertFromString("#FF8B8B8D"); gradientStop1 = new GradientStop(color, 0); color = (Color)ColorConverter.ConvertFromString("#FFB2B4B4"); gradientStop2 = new GradientStop(color, 2); break; } gradientStops.Add(gradientStop1); gradientStops.Add(gradientStop2); messageBorder.Background = new LinearGradientBrush(gradientStops, new Point(1, 0), new Point(1, 1)); }
public static GradientStopCollection FillGradients(GradientStopCollection stops) { GradientStopCollection result = new GradientStopCollection(); result.Add(stops[0]); for (int i = 1; i < stops.Count; i++) { GradientStop stop = stops[i]; GradientStop previous = stops[i - 1]; double progress = 0.5; double offset = previous.Offset + (stop.Offset - previous.Offset) * progress; Color color = HslConversion.Blend(previous.Color, stop.Color, progress); result.Add(new GradientStop(color, offset)); //if (Math.Abs(previous.Offset - stop.Offset) > float.Epsilon) //{ // for (int j = 1; j < 10; j++) // { // double progress = j / 10.0; // double offset = previous.Offset + (stop.Offset - previous.Offset) * progress; // Color color = HslConversion.Blend(previous.Color, stop.Color, progress); // result.Add(new GradientStop(color, offset)); // } //} result.Add(stop); } return(result); }
public static GradientBrush Convert(System.Windows.Media.Color color) { var scrgb = color.ToScRGBColor(); var xyz = KnownColorSpaces.scRGB.ToXYZColor(scrgb); var lab = KnownColorSpaces.Lab.FromXYZColor(xyz) as LabColor; var l_base = lab.L; var gradientStops = new GradientStopCollection(); var _lab = new LabColor(0xff, l_base * 1.07, lab.a, lab.b); var _c = _lab.ToWindowsMediaColor(); gradientStops.Add(new GradientStop(_c, 0.5)); _lab = new LabColor(0xff, l_base * .93, lab.a, lab.b); _c = _lab.ToWindowsMediaColor(); gradientStops.Add(new GradientStop(_c, 1)); var result = new LinearGradientBrush(gradientStops, 90); result.Freeze(); return result; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double value = double.Parse(values[0].ToString()); double maxValue = double.Parse(values[1].ToString()); if (value <= 0) { return(new SolidColorBrush(TRANSPARENT)); } if (value >= maxValue) { return(new SolidColorBrush(OPAQUE)); } double percentage = value / maxValue; GradientStopCollection gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop(OPAQUE, 0.0)); gradientStops.Add(new GradientStop(OPAQUE, percentage - 0.01)); gradientStops.Add(new GradientStop(TRANSPARENT, percentage + 0.01)); gradientStops.Add(new GradientStop(TRANSPARENT, 1.0)); return(new LinearGradientBrush(gradientStops, new Point(0.5, 1.0), new Point(0.5, 0.0))); }
private Brush GetColorFromShipRarity(string ShipRarity) { switch (ShipRarity) { case "Normal": return(new SolidColorBrush(Color.LightGray)); case "Rare": return(new SolidColorBrush((Color)colorConverter.ConvertFromInvariantString("#9fe8ff"))); case "Elite": return(new SolidColorBrush((Color)colorConverter.ConvertFromInvariantString("#c4adff"))); case "Super Rare": case "Priority": return(new SolidColorBrush((Color)colorConverter.ConvertFromInvariantString("#ee9"))); case "Ultra Rare": case "Decisive": var gradStopCollection = new GradientStopCollection(); Color tempColor = (Color)colorConverter.ConvertFromInvariantString("#fbffca"); gradStopCollection.Add(new GradientStop(tempColor, 0.0f)); tempColor = (Color)colorConverter.ConvertFromInvariantString("#baffbf"); gradStopCollection.Add(new GradientStop(tempColor, 0.33f)); tempColor = (Color)colorConverter.ConvertFromInvariantString("#a7efff"); gradStopCollection.Add(new GradientStop(tempColor, 0.66f)); tempColor = (Color)colorConverter.ConvertFromInvariantString("#ffabff"); gradStopCollection.Add(new GradientStop(tempColor, 1.0f)); return(new LinearGradientBrush(gradStopCollection, new Point(0, 0), new Point(1, 1))); default: return(null); } }
private LinearGradientBrush GetBrush() { LinearGradientBrush _brush = new LinearGradientBrush(); GradientStopCollection _grStops = new GradientStopCollection(); Random _rnd = new Random(DateTime.Now.Millisecond); Color _lightColor = new Color(); _lightColor.R = (byte)_rnd.Next(0, 255); _lightColor.G = (byte)_rnd.Next(0, 255); _lightColor.B = (byte)_rnd.Next(0, 255); Color _mediumColor = new Color(); _mediumColor.R = (byte)(_lightColor.R / 2); _mediumColor.G = (byte)(_lightColor.G / 2); _mediumColor.B = (byte)(_lightColor.G / 2); Color _darkColor = new Color(); _darkColor.R = (byte)(_lightColor.R / 3); _darkColor.G = (byte)(_lightColor.G / 3); _darkColor.B = (byte)(_lightColor.G / 3); _grStops.Add(new GradientStop(_mediumColor, 0)); _grStops.Add(new GradientStop(_lightColor, _rnd.Next(10) / 10f)); _grStops.Add(new GradientStop(_darkColor, 1)); _brush.GradientStops = _grStops; return(_brush); }
private void Timer_Tick(object sender, EventArgs e) { var minHeight = barContainer.ActualHeight * 0.1; bar.Height = (bar.Height - minHeight) * 0.9 + ((barContainer.ActualHeight - minHeight) * targetValue) * 0.1 + minHeight; if (confidence != targetConfidence) { confidence = confidence * 0.9 + targetConfidence * 0.1; if (Math.Abs(confidence - targetConfidence) < 0.0001) { confidence = targetConfidence; } Color bTransparent = Colors.CadetBlue; bTransparent.A = 0; GradientStopCollection gs = new GradientStopCollection(); gs.Add(new GradientStop(bTransparent, 0)); gs.Add(new GradientStop(Colors.CadetBlue, 1)); LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0, 0), new Point(0, bar.Height * (1 - confidence))); g.MappingMode = BrushMappingMode.Absolute; g.Freeze(); bar.Fill = g; } }
/// <summary> /// Adds the required <see cref="GradientStop"/>s to the gradient. /// </summary> /// <param name="gradientStops">The gradient.</param> /// <param name="startValue">The start value that corresponds to gradient offset 0.</param> /// <param name="previousEntry">The previous entry.</param> /// <param name="entry">The entry.</param> /// <param name="endValue">The end value that corresponds to gradient offset 1.</param> /// <param name="mode">The palette mode.</param> /// <remarks> /// This method adds all required <see cref="GradientStop"/>s from the previous up to the /// current entry. /// </remarks> private static void AddGradientStops(GradientStopCollection gradientStops, double startValue, PaletteEntry previousEntry, PaletteEntry entry, double endValue, PaletteMode mode) { Debug.Assert(gradientStops != null, "gradientStops must not be null."); Debug.Assert(startValue <= endValue, "startValue must be less than or equal to endValue."); double previousValue = previousEntry.Value; double nextValue = entry.Value; double offset; switch (mode) { case PaletteMode.Interpolate: offset = GetGradientStopOffset(startValue, previousValue, nextValue, endValue, 1.0); gradientStops.Add(new GradientStop { Color = entry.Color, Offset = offset }); break; case PaletteMode.GreaterOrEqual: offset = GetGradientStopOffset(startValue, previousValue, nextValue, endValue, 0.0); gradientStops.Add(new GradientStop { Color = entry.Color, Offset = offset }); offset = GetGradientStopOffset(startValue, previousValue, nextValue, endValue, 1.0); gradientStops.Add(new GradientStop { Color = entry.Color, Offset = offset }); break; case PaletteMode.LessOrEqual: offset = GetGradientStopOffset(startValue, previousValue, nextValue, endValue, 1.0); gradientStops.Add(new GradientStop { Color = previousEntry.Color, Offset = offset }); offset = GetGradientStopOffset(startValue, previousValue, nextValue, endValue, 1.0); gradientStops.Add(new GradientStop { Color = entry.Color, Offset = offset }); break; default: throw new ArgumentException("Unsupported palette mode."); } }
private static void ChangeFontStyle(TXT_ROOM item) { switch (item.STATES) { case "1": GradientStopCollection gc = new GradientStopCollection(); gc.Add(new GradientStop(Color.FromRgb(255, 166, 0), 0)); gc.Add(new GradientStop(Color.FromRgb(249, 41, 0), 0.5)); gc.Add(new GradientStop(Color.FromRgb(255, 166, 0), 1)); LinearGradientBrush gradientBrush = new LinearGradientBrush(gc); SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromRgb(249, 41, 0)); item.txtroomnum.Fill = gradientBrush; item.txtroomnum.Stroke = solidColorBrush; item.txtlanguage.Fill = gradientBrush; item.txtlanguage.Stroke = solidColorBrush; item.txtmorning.Fill = gradientBrush; item.txtmorning.Stroke = solidColorBrush; break; case "0": item.txtroomnum.Fill = Brushes.White; item.txtroomnum.Stroke = Brushes.Black; item.txtlanguage.Fill = Brushes.White; item.txtlanguage.Stroke = Brushes.Black; item.txtmorning.Fill = Brushes.White; item.txtmorning.Stroke = Brushes.Black; break; } }
private void DrawSquares() { if (Row >= 3) { startx += 5; } if (Row >= 6) { startx += 5; } int x = startx + (Row * 40); if (Column >= 3) { starty += 5; } if (Column >= 6) { starty += 5; } int y = starty + (Column * 37); SetValue(Canvas.LeftProperty, Convert.ToDouble(x)); SetValue(Canvas.TopProperty, Convert.ToDouble(y)); GradientStopCollection gradients = new GradientStopCollection(); if (Value != 0) { gradients.Add(new GradientStop(Colors.LightBlue, 1)); gradients.Add(new GradientStop(Color.FromArgb(38, 255, 255, 255), 0.448)); gradients.Add(new GradientStop(Color.FromArgb(90, 73, 73, 73), 0.076)); SudokuTextBox.Text = Value.ToString(); SudokuTextBox.IsEnabled = false; } else { gradients.Add(new GradientStop(Colors.LightGreen, 0.9)); gradients.Add(new GradientStop(Colors.White, 0.448)); gradients.Add(new GradientStop(Colors.LightGreen, 0.076)); } SudokuTextBox.BorderThickness = new Thickness(0); SudokuTextBox.TextAlignment = TextAlignment.Center; LinearGradientBrush brush = new LinearGradientBrush(gradients); brush.StartPoint = new Point(0.5, 0); brush.EndPoint = new Point(0.5, 1); SudokuRectangle.Fill = brush; SudokuRectangle.Stroke = Brushes.Gray; SudokuRectangle.StrokeThickness = 1; SudokuRectangle.RadiusX = 8; SudokuRectangle.RadiusY = 8; SudokuTextBox.TextChanged += new TextChangedEventHandler(SudokuTextBox_TextChanged); }
public override void SaveGradient() { double rate = DataManager.Instance.MainData.PixelWidth / _bokehData.Width; GradientStopCollection collection = new GradientStopCollection(); collection.Add(new GradientStop() { Color = Colors.Transparent, Offset = _bokehData.Rate }); collection.Add(new GradientStop() { Color = Color.FromArgb(128, 0, 0, 0), Offset = _bokehData.Rate }); collection.Add(new GradientStop() { Color = Color.FromArgb(255, 0, 0, 0), Offset = 1 }); RadialGradientBrush brush = new RadialGradientBrush() { GradientOrigin = _bokehData.StarPoint, Center = _bokehData.StarPoint, RadiusX = _bokehData.RadiusX, RadiusY = _bokehData.RadiusY, GradientStops = collection, }; Rectangle rectangle = new Rectangle() { Width = DataManager.Instance.MainData.PixelWidth, Height = DataManager.Instance.MainData.PixelHeight, Fill = _bokehData.MaskBrush, OpacityMask = brush }; Canvas saveCanvas = new Canvas() { Width = rectangle.Width, Height = rectangle.Height, Background = new ImageBrush() { ImageSource = DataManager.Instance.MainData }, }; saveCanvas.Children.Add(rectangle); WriteableBitmap bmp = new WriteableBitmap(saveCanvas, null); DataManager.Instance.SaveToFile(bmp); }
/// <summary> /// Handles the Loaded event of the UserControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void UserControl_Loaded(object sender, RoutedEventArgs e) { this.unselectedFilterBrush = (Brush)this.FilterPastButton.Background; // Setting the unselected look to the default look linear gradient brush this.FilterDropDown.SelectedIndex = -1; this.FilterDropDown.SelectionChanged += new SelectionChangedEventHandler(this.DropPastListBox_SelectionChanged); if (null != this.buttonStyle) { this.CurrentButton.Style = this.buttonStyle; this.FilterPastButton.Style = this.buttonStyle; } #if !SILVERLIGHT GradientStopCollection gSc = new GradientStopCollection(); gSc.Add(new GradientStop() { Offset = 0.986, Color = Color.FromArgb(255, 252, 245, 224) }); gSc.Add(new GradientStop() { Offset = 0.01, Color = Color.FromArgb(255, 252, 196, 83) }); gSc.Add(new GradientStop() { Offset = 0, Color = Color.FromArgb(255, 248, 246, 242) }); this.selectedFilterBrush = new LinearGradientBrush(gSc); #endif this.FilterCurrentButton.Background = this.selectedFilterBrush; }
public static Brush GetBrushForDistribution(WebLibraryDetail web_library_detail, int num_topics, float[] distribution) { ExpeditionDataSource eds = web_library_detail.Xlibrary?.ExpeditionManager?.ExpeditionDataSource; if (null != eds) { Color[] colours = eds.Colours; int num_stops = 2 * num_topics; GradientStopCollection gradient_stop_collection = new GradientStopCollection(num_stops); double previous_offset = 0.0; for (int i = 0; i < num_topics; ++i) { gradient_stop_collection.Add(new GradientStop(colours[i], previous_offset)); previous_offset += distribution[i]; gradient_stop_collection.Add(new GradientStop(colours[i], previous_offset)); } LinearGradientBrush lgb = new LinearGradientBrush(gradient_stop_collection); lgb.Freeze(); return(lgb); } return(UNKNOWN_BRUSH); }
public object Convert(object value, Type targetType, object parameter, string language) { try { ObservableCollection <ColorItem> colors = (ObservableCollection <ColorItem>)value; GradientStopCollection GradientItems = new GradientStopCollection(); foreach (ColorItem colorItem in colors) { GradientItems.Add(new GradientStop { Color = colorItem.Color, Offset = colorItem.Offset }); } return(GradientItems); } catch { Debug.WriteLine("GradientPreview had an error converting"); GradientStopCollection GradientItems = new GradientStopCollection(); GradientItems.Add(new GradientStop { Color = Colors.Red, Offset = 0 }); GradientItems.Add(new GradientStop { Color = Colors.Blue, Offset = 1 }); return(GradientItems); } }
private GradientStopCollection CreateStops(Color c, double cornerRadius) { double stopPoint = 1.0 / (cornerRadius + ShadowDepth); var stops = new GradientStopCollection { new GradientStop(c, (ShadowDepth + cornerRadius) * stopPoint) }; Color color = c; color.A = (byte)(0.74336 * c.A); stops.Add(new GradientStop(color, (1.5 + cornerRadius) * stopPoint)); color.A = (byte)(0.38053 * c.A); stops.Add(new GradientStop(color, (2.5 + cornerRadius) * stopPoint)); color.A = (byte)(0.12389 * c.A); stops.Add(new GradientStop(color, (3.5 + cornerRadius) * stopPoint)); color.A = (byte)(0.02654 * c.A); stops.Add(new GradientStop(color, (4.5 + cornerRadius) * stopPoint)); color.A = 0; stops.Add(new GradientStop(color, (5.0 + cornerRadius) * stopPoint)); stops.Freeze(); return(stops); }
private void OnMouseLeave(object sender, RoutedEventArgs e) { GradientStopCollection stopCollection = new GradientStopCollection(); stopCollection.Add(new GradientStop(Colors.Blue, 0.05)); stopCollection.Add(new GradientStop(Colors.LightBlue, 0.95)); RadialGradientBrush brush = new RadialGradientBrush(stopCollection); circle.Fill = brush; }
protected Brush CreateGradientBrush(Color baseColor) { const byte brightness = 60; var gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop() { Color = LightenColor(baseColor, brightness), Offset = 0.0 }); gradientStops.Add(new GradientStop() { Color = baseColor, Offset = 1.0 }); return new LinearGradientBrush(gradientStops, 90); }
private void OnOneClick(object sender, RoutedEventArgs e) { RadialGradientBrush brush = this.Resources["redBrush"] as RadialGradientBrush; var gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop(Colors.LightBlue, 0)); gradientStops.Add(new GradientStop(Colors.DarkBlue, 1)); LinearGradientBrush newBrush = new LinearGradientBrush(gradientStops); this.Resources["redBrush"] = newBrush; }
public BrushEditor() { GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop(Colors.Black, 0)); stops.Add(new GradientStop(Colors.White, 1)); linearGradientBrush = new LinearGradientBrush(stops); linearGradientBrush.EndPoint = new Point(1, 0); radialGradientBrush = new RadialGradientBrush(stops); }
private void SetGradient(Color topColor, Color bottomColor) { GradientStopCollection gradients = new GradientStopCollection(); gradients.Add(new GradientStop(topColor, 0.9)); gradients.Add(new GradientStop(Colors.WhiteSmoke, 0.448)); gradients.Add(new GradientStop(bottomColor, 0.076)); LinearGradientBrush brush = new LinearGradientBrush(gradients); brush.StartPoint = new Point(0.5, 0); brush.EndPoint = new Point(0.5, 1); SudokuRectangle.Fill = brush; }
public void AssocColor(string seriesId, Color b) { Color bTransparent = b; bTransparent.A = 0; GradientStopCollection gs = new GradientStopCollection(); gs.Add(new GradientStop(bTransparent, 0)); gs.Add(new GradientStop(b, 0.1)); LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0,0), new Point(ActualWidth, 0)); g.MappingMode = BrushMappingMode.Absolute; g.Freeze(); brushes[seriesId] = g; }
/// <summary> /// Handles the click event on the Koch Snowflake button /// </summary> /// <param name="sender">The object generating the event</param> /// <param name="e">RoutedEventArgs event arguments</param> private void BtnSnowflake_Click(object sender, RoutedEventArgs e) { // set up the canvas background brush and instantiate the window with it GradientStopCollection gradStop = new GradientStopCollection(); gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF88ADD8"), 0.947)); gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF235087"), 0.992)); gradStop.Add(new GradientStop(Colors.White, 0)); RadialGradientBrush brushBG = new RadialGradientBrush(gradStop); FractalWindow winFrac = new FractalWindow(brushBG); // setup the fractal we're going to draw and put it in the FractalWindow object LineBendingFractal fractal = new LineBendingFractal(); winFrac.HostedFractal = fractal; winFrac.Show(); }
/// <summary> /// Converts the color of the supplied brush changing its luminosity by the given factor. /// </summary> /// <param name="value">The value that is produced by the binding target.</param> /// <param name="targetType">The type to convert to.</param> /// <param name="parameter">The factor used to adjust the luminosity (0..1).</param> /// <param name="culture">The culture to use in the converter (unused).</param> /// <returns>A converted value.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) #endif { if (value == null) return null; if (parameter == null) return null; var factor = double.Parse(parameter.ToString(), CultureInfo.InvariantCulture); if (value is SolidColorBrush) { var color = ((SolidColorBrush)value).Color; var hlsColor = HlsColor.FromRgb(color); hlsColor.L *= factor; return new SolidColorBrush(hlsColor.ToRgb()); } else if (value is LinearGradientBrush) { var gradientStops = new GradientStopCollection(); foreach (var stop in ((LinearGradientBrush)value).GradientStops) { var hlsColor = HlsColor.FromRgb(stop.Color); hlsColor.L *= factor; gradientStops.Add(new GradientStop() { Color = hlsColor.ToRgb(), Offset = stop.Offset }); } var brush = new LinearGradientBrush(gradientStops, 0.0); return brush; } return value; }
//public override double Temperature //{ // set // { // base.Temperature = value; // Canvas.SetTop(fillRect, 85.0 - base.Temperature); // fillRect.Height = base.Temperature; // bool flag = !MinTemperature; // if (!flag) // { // fillRect.Fill = Brushes.Blue; // } // else // { // flag = !MaxTemperature; // if (!flag) // fillRect.Fill = Brushes.Red; // else // fillRect.Fill = Brushes.Green; // } // } //} public Tank() : base(new Dictionary<String, Parameter>() { { "Temperature", new Parameter(0.0, 0.0, 100.0, ".T") }, { "Level", new Parameter(0.0, 0.0, 60.0, ".L") } }) { ellipseTop = new Ellipse(); ellipseBottom = new Ellipse(); backRect = new Rectangle(); fillRect = new Rectangle(); Canvas.SetLeft(ellipseTop, 0.0); Canvas.SetTop(ellipseTop, 0.0); ellipseTop.Width = 100.0; ellipseTop.Height = 20.0; GradientStopCollection gradientStopCollection = new GradientStopCollection(); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 200, 190, 160), 0.0)); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 100, 90, 60), 1.0)); ellipseTop.Fill = new LinearGradientBrush(gradientStopCollection); Canvas.SetLeft(ellipseBottom, 0.0); Canvas.SetTop(ellipseBottom, 80.0); ellipseBottom.Width = 100.0; ellipseBottom.Height = 20.0; gradientStopCollection = new GradientStopCollection(); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 200, 190, 160), 0.0)); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 100, 90, 60), 1.0)); ellipseBottom.Fill = new LinearGradientBrush(gradientStopCollection); Canvas.SetLeft(backRect, 0.0); Canvas.SetTop(backRect, 10.0); backRect.Width = 100.0; backRect.Height = 80.0; gradientStopCollection = new GradientStopCollection(); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 200, 190, 160), 0.0)); gradientStopCollection.Add(new GradientStop(Color.FromArgb(255, 100, 90, 60), 1.0)); backRect.Fill = new LinearGradientBrush(gradientStopCollection); Canvas.SetLeft(fillRect, 5.0); fillRect.Width = 90.0; Children.Add(ellipseTop); Children.Add(ellipseBottom); Children.Add(backRect); Children.Add(fillRect); Update(); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double value = double.Parse(values[0].ToString()); double maxValue = double.Parse(values[1].ToString()); if (value <= 0) return new SolidColorBrush(TRANSPARENT); if (value >= maxValue) return new SolidColorBrush(OPAQUE); double percentage = value / maxValue; GradientStopCollection gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop(OPAQUE, 0.0)); gradientStops.Add(new GradientStop(OPAQUE, percentage - 0.01)); gradientStops.Add(new GradientStop(TRANSPARENT, percentage + 0.01)); gradientStops.Add(new GradientStop(TRANSPARENT, 1.0)); return new LinearGradientBrush(gradientStops, new Point(0.5, 1.0), new Point(0.5, 0.0)); }
/// <summary> /// Handles the click event on the Binary Tree button /// </summary> /// <param name="sender">The object generating the event</param> /// <param name="e">RoutedEventArgs event arguments</param> private void BtnTree_Click(object sender, RoutedEventArgs e) { // set up the canvas background brush and instantiate the window with it GradientStopCollection gradStop = new GradientStopCollection(); gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF2499FA"), 0.529)); gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF683205"), 1)); LinearGradientBrush brushBG = new LinearGradientBrush(gradStop, new Point(0.5, 0), new Point(0.5, 1)); FractalWindow winFrac = new FractalWindow(brushBG); // setup the fractal we're going to draw and put it in a new FractalWindow object SymmetricTreeFractal fractal = new SymmetricTreeFractal(10, 1, 5); ////fractal.ChildOffset = 0.2; ////fractal.ChildOffsetRotation = 3 * Math.PI / 2; ////fractal.DrawSpeed = 1; ////fractal.DeltaTheta = 2 * (Math.PI / 5); ////fractal.ChildCount = 4; winFrac.HostedFractal = fractal; winFrac.Show(); }
/// <summary>${WP_mapping_HeatMapLayer_constructor_None_D}</summary> public HeatMapLayer() { heatPoints = new HeatPointCollection(); heatPoints.CollectionChanged += new NotifyCollectionChangedEventHandler(heatPoints_CollectionChanged); fullBounds = Rectangle2D.Empty; //设置GradientStops的默认值 GradientStopCollection stops = new GradientStopCollection(); stops.Add(new GradientStop() { Color = Color.FromArgb(0, 0, 0, 0), Offset = 0 }); stops.Add(new GradientStop() { Color = new Color() { A = 0xff, R = 0xff, G = 0x42, B = 0x00 }, Offset = 0.75 }); stops.Add(new GradientStop() { Color = new Color() { A = 0xff, R = 0xff, G = 0xff, B = 0x00 }, Offset = .5 }); stops.Add(new GradientStop() { Color = new Color() { A = 0xff, R = 0x1a, G = 0xa4, B = 0x03 }, Offset = .25 }); GradientStops = stops; //初始化后台线程 worker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.DoWork += new DoWorkEventHandler(worker_DoWork); }
public void CollectionCtorSingle () { GradientStopCollection gsc = new GradientStopCollection (); gsc.Add (new GradientStop ()); RadialGradientBrush rgb = new RadialGradientBrush (gsc); Assert.IsTrue (Object.ReferenceEquals (gsc, rgb.GradientStops), "Same GradientStops"); GradientStop gs1 = rgb.GradientStops [0]; Assert.AreEqual ("#00000000", gs1.Color.ToString (), "1.Color"); Assert.AreEqual (0.0, gs1.Offset, "1.Offset"); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { if (value.ToString().Equals("White")) { return new SolidColorBrush(Colors.White); } else if (value.ToString().Equals("Black")) { return new SolidColorBrush(Colors.Black); } else if (value.ToString().Equals("Silver")) { return new SolidColorBrush(Colors.Silver); } else if (value.ToString().Equals("Blue")) { return new SolidColorBrush(Colors.Blue); } else if (value.ToString().Equals("Red")) { return new SolidColorBrush(Colors.Red); } else if (value.ToString().Equals("Yellow")) { return new SolidColorBrush(Colors.Yellow); } else if (value.ToString().Equals("Multi")) { GradientStopCollection gradients = new GradientStopCollection(); gradients.Add(new GradientStop(Colors.Red, 0.0)); gradients.Add(new GradientStop(Colors.Yellow, 0.25)); gradients.Add(new GradientStop(Colors.Green, 0.50)); gradients.Add(new GradientStop(Colors.Blue, 0.75)); gradients.Add(new GradientStop(Colors.Purple, 1.0)); return new LinearGradientBrush(gradients); } } return null; }
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height) { var gradientStops = new GradientStopCollection(); gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0)); gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0.5)); gradientStops.Add(new GradientStop(SWMColor.FromArgb(180, 0, 0, 0), 1.3)); gradientStops.Add(new GradientStop(SWMColor.FromArgb(230, 0, 0, 0), 1.7)); var brush = new RadialGradientBrush(gradientStops) { GradientOrigin = new Point(0.5, 0.5), Center = new Point(0.5, 0.45), RadiusX = 0.5, RadiusY = 0.5 }; dc.DrawImage(source.InnerBitmap, new Rect(0, 0, width, height)); dc.PushOpacityMask(brush); dc.DrawRectangle(new SolidColorBrush(SWMColors.Black), null, new Rect(0, 0, width, height)); dc.Pop(); }
public static LinearGradientBrush GetAlphaLinearGradientBrush1(Color color) { //Color.FromScRgb(0.44f, color.ScR, color.ScG, color.ScB) //GetAlphaColor(color, 0.44f) LinearGradientBrush brush = new LinearGradientBrush(); brush.StartPoint = new System.Windows.Point(0, 0); brush.EndPoint = new System.Windows.Point(0, 1.5); GradientStopCollection gradientStopCollection = new GradientStopCollection(); GradientStop stop1 = new GradientStop(GetAlphaColor(color, 0.44f), 0); GradientStop stop2 = new GradientStop(GetAlphaColor(color, 0.44f), 0.30); GradientStop stop3 = new GradientStop(color, 0.31); GradientStop stop4 = new GradientStop(Colors.White, 1); gradientStopCollection.Add(stop1); gradientStopCollection.Add(stop2); gradientStopCollection.Add(stop3); gradientStopCollection.Add(stop4); brush.GradientStops = gradientStopCollection; //brush.Freeze(); return brush; }
// *** Private static methods *** private static void CreateBrushes() { // Get the colors for the shadow Color shadowColor = Color.FromArgb(128, 0, 0, 0); Color transparentColor = Color.FromArgb(16, 0, 0, 0); // Create a GradientStopCollection from these GradientStopCollection gradient = new GradientStopCollection(2); gradient.Add(new GradientStop(shadowColor, 0.5)); gradient.Add(new GradientStop(transparentColor, 1.0)); gradient.Freeze(); // Create the background brush backgroundBrush = new SolidColorBrush(shadowColor); backgroundBrush.Freeze(); // Create the LinearGradientBrushes rightBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(1.0, 0.0)); rightBrush.Freeze(); bottomBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(0.0, 1.0)); bottomBrush.Freeze(); // Create the RadialGradientBrushes bottomRightBrush = new RadialGradientBrush(gradient); bottomRightBrush.GradientOrigin = new Point(0.0, 0.0); bottomRightBrush.Center = new Point(0.0, 0.0); bottomRightBrush.RadiusX = 1.0; bottomRightBrush.RadiusY = 1.0; bottomRightBrush.Freeze(); topRightBrush = new RadialGradientBrush(gradient); topRightBrush.GradientOrigin = new Point(0.0, 1.0); topRightBrush.Center = new Point(0.0, 1.0); topRightBrush.RadiusX = 1.0; topRightBrush.RadiusY = 1.0; topRightBrush.Freeze(); bottomLeftBrush = new RadialGradientBrush(gradient); bottomLeftBrush.GradientOrigin = new Point(1.0, 0.0); bottomLeftBrush.Center = new Point(1.0, 0.0); bottomLeftBrush.RadiusX = 1.0; bottomLeftBrush.RadiusY = 1.0; bottomLeftBrush.Freeze(); }
public LinearGradientBrush GetBrush() { var gradientStops = new GradientStopCollection(); foreach (var gs in Stops.Select(ps => new GradientStop {Color = ps.Color, Offset = ps.StopValue})) { gradientStops.Add(gs); } //rect.Fill = new LinearGradientBrush(stops); var linbrush = new LinearGradientBrush {GradientStops = gradientStops}; linbrush.StartPoint = new Point(0,0); linbrush.EndPoint = new Point(1,0); return linbrush; }
public ChartCanvas() { RebuildDisabled = true; //Background = new SolidColorBrush(Color.FromArgb(0xf0, 0x3f, 0x3f, 0x3f)); GradientStopCollection gradient = new GradientStopCollection(); gradient.Add(new GradientStop(Color.FromRgb(203, 231, 227), 0)); gradient.Add(new GradientStop(Color.FromRgb(241, 230, 168), 0.6)); gradient.Add(new GradientStop(Color.FromRgb(236, 213, 186), 1)); LinearGradientBrush back = new LinearGradientBrush(gradient, new Point(0,0), new Point(0, 1)); Background = back; Offset = 0; XRange = 50; CandleWidth = 9; CandleSpacing = 3; YMin = 0; YMax = 100; LeftMargin = 10; RightMargin = 40; TopMargin = 10; BottomMargin = 10; _gridPattern = new DoubleCollection(2); _gridPattern.Add(5); _gridPattern.Add(5); ShowGridLines(); this.PreviewMouseLeftButtonDown += CustomCanvas_PreviewMouseLeftButtonDown; this.PreviewMouseLeftButtonUp += CustomCanvas_PreviewMouseLeftButtonUp; this.PreviewMouseMove += CustomCanvas_PreviewMouseMove; this.SizeChanged += ChartCanvas_SizeChanged; RebuildDisabled = false; }
/// <summary> /// Parses a sequence of GradientStop element. /// </summary> GradientStopCollection ParseGradientStops() { GradientStopCollection gradientStops = new GradientStopCollection(); if (!this.reader.IsEmptyElement) { MoveToNextElement(); while (this.reader.IsStartElement()) { GradientStop gs = ParseGradientStop(); gradientStops.Add(gs); } MoveToNextElement(); } return gradientStops; }
private void Timer_Tick(object sender, EventArgs e) { var minHeight = barContainer.ActualHeight * 0.1; bar.Height = (bar.Height-minHeight) * 0.9 + ((barContainer.ActualHeight-minHeight) * targetValue) * 0.1 + minHeight; if (confidence != targetConfidence) { confidence = confidence * 0.9 + targetConfidence * 0.1; if (Math.Abs(confidence - targetConfidence) < 0.0001) confidence = targetConfidence; Color bTransparent = Colors.CadetBlue; bTransparent.A = 0; GradientStopCollection gs = new GradientStopCollection(); gs.Add(new GradientStop(bTransparent, 0)); gs.Add(new GradientStop(Colors.CadetBlue, 1)); LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0, 0), new Point(0, bar.Height*(1-confidence))); g.MappingMode = BrushMappingMode.Absolute; g.Freeze(); bar.Fill = g; } }
private static GradientStopCollection createGradientStopCollection(Color[] colors) { GradientStopCollection stops = new GradientStopCollection(); if (colors != null) { double[] offsets = null; if (colors.Length == 5) offsets = new double[] { 0, 0.5, 0.75, 0.8, 1 }; else if (colors.Length == 7) offsets = new double[] { 0, 1, 0.864, 0.708, 0.53, 0.36, 0.18 }; int i = 0; foreach (Color clr in colors) { stops.Add(new GradientStop() { Color = clr, Offset = offsets[i] }); i++; } } return stops; }
private EnumerableDataSource<DataPoint> CreateDataSource(IEnumerable<DataPoint> data) { EnumerableDataSource<DataPoint> ds = new EnumerableDataSource<DataPoint>(data); MercatorTransform transform = new MercatorTransform(); ds.SetXMapping(p => p.X); ds.SetYMapping(p => transform.DataToViewport(new Point(0, p.Y)).Y); ds.AddMapping(CirclePointMarker.FillProperty, dp => { double alpha = (dp.Data - currentRange.Min) / (currentRange.Max - currentRange.Min); Debug.Assert(0 <= alpha && alpha <= 1); const double hueWidth = 100; double hue = hueWidth * (alpha - 0.5) + hueSlider.Value; if (hue > 360) hue -= 360; else if (hue < 0) hue += 360; Debug.Assert(0 <= hue && hue <= 360); Color mainColor = new HsbColor(hue, 1, 0 + 1 * alpha, 0.3 + 0.7 * alpha).ToArgbColor(); const int colorCount = 5; GradientStopCollection colors = new GradientStopCollection(colorCount); double step = 1.0 / (colorCount - 1); for (int i = 0; i < colorCount; i++) { Color color = mainColor; double x = attSlider.Value * step * i; color.A = (byte)(255 * Math.Exp(-x * x)); colors.Add(new GradientStop(color, step * i)); } return new RadialGradientBrush(colors); }); return ds; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { double offset = double.Parse(values[0].ToString()); double maxHeight = double.Parse(values[1].ToString()); double height = double.Parse(values[2].ToString()); double transparencyHeight = double.Parse(parameter.ToString()); double transparencyFactor = (transparencyHeight - 6) / height; double transparencyFadeFactor = (transparencyHeight + 4) / height; bool top = !(Math.Abs(offset) < float.Epsilon); bool bot = !(Math.Abs(offset - maxHeight) < float.Epsilon); if (!top && !bot) return new SolidColorBrush(OPAQUE); GradientStopCollection gradientStops = new GradientStopCollection(); if (top) { gradientStops.Add(new GradientStop(TRANSPARENT, 0.0)); gradientStops.Add(new GradientStop(TRANSPARENT, transparencyFactor)); gradientStops.Add(new GradientStop(OPAQUE, transparencyFadeFactor)); } else gradientStops.Add(new GradientStop(OPAQUE, 0.0)); if (bot) { gradientStops.Add(new GradientStop(OPAQUE, 1.0 - transparencyFadeFactor)); gradientStops.Add(new GradientStop(TRANSPARENT, 1.0 - transparencyFactor)); gradientStops.Add(new GradientStop(TRANSPARENT, 1.0)); } else gradientStops.Add(new GradientStop(OPAQUE, 1.0)); return new LinearGradientBrush(gradientStops, new Point(0.5, 0.0), new Point(0.5, 1.0)); }
private GradientStopCollection GetStopCollection() { var collection = new GradientStopCollection(); var numberOfSections = (colors.Count - 2) / AllColors.Count + 1; var stops = new List<GradientStop>(); double stepSize; if(numberOfSections == 1) stepSize = 0; else stepSize = 1/((double)numberOfSections - 1); for (var i = 0; i < numberOfSections; i++) { var stop = new GradientStop {Color = NextFreeColor(i), Offset = (stepSize * i)}; stops.Add(stop); } foreach (var gradientStop in stops) { collection.Add(gradientStop); } return collection; }