public Color GetColorForSpeed(float speed) { if (speed > 0) { lock (speedColorLookup) { double startColor = 223.0 / 360.0; double endColor = 5.0 / 360.0; double delta = startColor - endColor; if (!speedColorLookup.ContainsKey(speed)) { Color color = ColorF.FromHSL(startColor, .99, .49).ToColor(); speedColorLookup.Add(speed, color); if (speedColorLookup.Count > 1) { double step = delta / (speedColorLookup.Count - 1); for (int index = 0; index < speedColorLookup.Count; index++) { double offset = step * index; double fixedColor = startColor - offset; KeyValuePair <float, Color> keyValue = speedColorLookup.ElementAt(index); speedColorLookup[keyValue.Key] = ColorF.FromHSL(fixedColor, .99, .49).ToColor(); } } } return(speedColorLookup[speed]); } } return(Color.Black); }
public ColorSwatchSelector(ThemeConfig theme, BorderDouble buttonSpacing, int buttonSize = 32, Action <Color> colorNotifier = null) : base(FlowDirection.TopToBottom) { var scaledButtonSize = buttonSize * GuiWidget.DeviceScale; int colorCount = 9; double[] lightness = new double[] { .7, .5, .3 }; Action <Color> colorChanged = (color) => { colorNotifier?.Invoke(color); }; var grayLevel = new Color[] { Color.White, new Color(180, 180, 180), Color.Gray }; for (int rowIndex = 0; rowIndex < lightness.Length; rowIndex++) { var colorRow = new FlowLayoutWidget(); AddChild(colorRow); for (int colorIndex = 0; colorIndex < colorCount; colorIndex++) { var color = ColorF.FromHSL(colorIndex / (double)colorCount, 1, lightness[rowIndex]).ToColor(); colorRow.AddChild(MakeColorButton(color, scaledButtonSize, buttonSpacing, colorChanged)); } // put in white and black buttons colorRow.AddChild(MakeColorButton(grayLevel[rowIndex], scaledButtonSize, buttonSpacing, colorChanged)); switch (rowIndex) { case 0: var resetButton = new IconButton(StaticData.Instance.LoadIcon("transparent_grid.png"), theme) { Width = scaledButtonSize, Height = scaledButtonSize, Margin = buttonSpacing, VAnchor = VAnchor.Absolute }; resetButton.Click += (s, e) => { // The colorChanged action displays the given color - use .MinimalHighlight rather than no color colorChanged(Color.Transparent); }; colorRow.AddChild(resetButton); break; case 1: colorRow.AddChild(MakeColorButton(new Color("#555"), scaledButtonSize, buttonSpacing, colorChanged)); break; case 2: colorRow.AddChild(MakeColorButton(new Color("#222"), scaledButtonSize, buttonSpacing, colorChanged)); break; } } }
public void BuildHistogramFromImage(ImageBuffer image, ImageToPathObject3D_2.AnalysisTypes analysisType) { // build the histogram cache var height = (int)(100 * GuiWidget.DeviceScale); _histogramRawCache = new ImageBuffer(256, height); var counts = new int[_histogramRawCache.Width]; IThresholdFunction function = new MapOnMaxIntensity(0, 1); var bottom = 0; if (analysisType == ImageToPathObject3D_2.AnalysisTypes.Colors) { function = new QuickHue(); bottom = (int)(10 * GuiWidget.DeviceScale); } byte[] buffer = image.GetBuffer(); for (int y = 0; y < image.Height; y++) { int imageBufferOffset = image.GetBufferOffsetY(y); for (int x = 0; x < image.Width; x++) { int imageBufferOffsetWithX = imageBufferOffset + x * 4; var color = GetRGBA(buffer, imageBufferOffsetWithX); counts[(int)(function.Transform(color) * (_histogramRawCache.Width - 1))]++; } } double max = counts.Select((value, index) => new { value, index }) .OrderByDescending(vi => vi.value) .First().value; var graphics = _histogramRawCache.NewGraphics2D(); var theme = ApplicationController.Instance.Theme; graphics.Clear(theme.SlightShade); var graphShape = new VertexStorage(); var graphHeight = height - bottom; graphShape.MoveTo(0, bottom); for (int i = 0; i < 256; i++) { graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + Easing.Cubic.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + counts[i] / max * graphHeight); } graphShape.LineTo(256, bottom); graphShape.LineTo(0, bottom); graphics.Render(graphShape, 0, 0, theme.TextColor); for (int i = 0; i < 256; i++) { var hue = ColorF.FromHSL(i / 255.0, 1, .49).ToColor(); graphics.Line(i, 0, i, bottom, hue); } }
private Color ComputeColor(float speed) { var rangedValue = speed - min; var factor = range == 0 ? 1 : rangedValue / range; double offset = factor * delta; double fixedColor = startColor - offset; return(ColorF.FromHSL(fixedColor, .99, .49).ToColor()); }
public ColorSwatchSelector(InteractiveScene scene, ThemeConfig theme, BorderDouble buttonSpacing, int buttonSize = 32) : base(FlowDirection.TopToBottom) { var scaledButtonSize = buttonSize * GuiWidget.DeviceScale; int colorCount = 9; double[] lightness = new double[] { .7, .5, .3 }; var grayLevel = new Color[] { Color.White, new Color(180, 180, 180), Color.Gray }; for (int rowIndex = 0; rowIndex < lightness.Length; rowIndex++) { var colorRow = new FlowLayoutWidget(); AddChild(colorRow); for (int colorIndex = 0; colorIndex < colorCount; colorIndex++) { var color = ColorF.FromHSL(colorIndex / (double)colorCount, 1, lightness[rowIndex]).ToColor(); colorRow.AddChild(MakeColorButton(scene, color, scaledButtonSize, buttonSpacing)); } // put in white and black buttons colorRow.AddChild(MakeColorButton(scene, grayLevel[rowIndex], scaledButtonSize, buttonSpacing)); switch (rowIndex) { case 0: var resetButton = new IconButton(AggContext.StaticData.LoadIcon("transparent_grid.png"), theme) { Width = scaledButtonSize, Height = scaledButtonSize, Margin = buttonSpacing, VAnchor = VAnchor.Absolute }; resetButton.Click += (s, e) => { scene.UndoBuffer.AddAndDo(new ChangeColor(scene.SelectedItem, Color.Transparent)); }; colorRow.AddChild(resetButton); break; case 1: colorRow.AddChild(MakeColorButton(scene, new Color("#555"), scaledButtonSize, buttonSpacing)); break; case 2: colorRow.AddChild(MakeColorButton(scene, new Color("#222"), scaledButtonSize, buttonSpacing)); break; } } }
public static Color GetMaterialColor(int materialIndexBase1) { lock (materialColors) { if (materialColors.ContainsKey(materialIndexBase1)) { return(materialColors[materialIndexBase1]); } } // we currently expect at most 4 extruders return(ColorF.FromHSL((materialIndexBase1 % 4) / 4.0, .5, .5).ToColor()); }
public static Color GetSelectedMaterialColor(int materialIndexBase1) { double hue0To1; double saturation0To1; double lightness0To1; GetMaterialColor(materialIndexBase1).ToColorF().GetHSL(out hue0To1, out saturation0To1, out lightness0To1); // now make it a bit lighter and less saturated saturation0To1 = Math.Min(1, saturation0To1 * 2); lightness0To1 = Math.Min(1, lightness0To1 * 1.2); // we sort of expect at most 4 extruders return(ColorF.FromHSL(hue0To1, saturation0To1, lightness0To1).ToColor()); }
public static void EnsureUpdated(Mesh meshToRender, Matrix4X4 transform) { var faces = meshToRender.Faces; if (faces?.Count < 1) { return; } if (!meshToRender.PropertyBag.ContainsKey("Face0WorldZAngle")) { meshToRender.PropertyBag.Add("Face0WorldZAngle", new NormalZ()); } var normalZ = meshToRender.PropertyBag["Face0WorldZAngle"] as NormalZ; var face0Normal = faces[0].normal.TransformNormal(transform).GetNormal(); var error = .0001; if (normalZ.z < face0Normal.Z - error || normalZ.z > face0Normal.Z + error) { meshToRender.MarkAsChanged(); normalZ.z = face0Normal.Z; } // change the color to be the right thing per face normal GLMeshTrianglePlugin.Get( meshToRender, (normal) => { normal = normal.TransformNormal(transform).GetNormal(); double startColor = 223.0 / 360.0; double endColor = 5.0 / 360.0; double delta = endColor - startColor; var polyColor = ColorF.FromHSL(startColor, .99, .49).ToColor(); if (normal.Z < 0) { polyColor = ColorF.FromHSL(startColor - delta * normal.Z, .99, .49).ToColor(); } return(polyColor); }); }
public static Color InvertColor(Color color) { ColorF colorFloat = new ColorF(color); double hue0To1; double saturation0To1; double lightness0To1; colorFloat.GetHSL(out hue0To1, out saturation0To1, out lightness0To1); ColorF colorInvertedFloat = ColorF.FromHSL(hue0To1, saturation0To1, 1 - lightness0To1); Color invertedColor = new Color( colorInvertedFloat.Red0To255, colorInvertedFloat.Green0To255, colorInvertedFloat.Blue0To255, // and don't change the alpha value color.alpha); return(invertedColor); }
/// <summary> /// Get the color for a given extruder, falling back to the supplied color on -1 (unassigned) /// </summary> /// <param name="materialIndex">The extruder/material index to resolve</param> /// <param name="unassignedColor">The color to use when the extruder/material has not been assigned</param> /// <returns>The color for the given extruder</returns> public static Color Color(PrinterConfig printer, int materialIndex, Color unassignedColor) { if (printer?.Settings != null) { switch (materialIndex) { case 0: return(new Color(printer.Settings.GetValue(SettingsKey.material_color))); case 1: return(new Color(printer.Settings.GetValue(SettingsKey.material_color_1))); case 2: return(new Color(printer.Settings.GetValue(SettingsKey.material_color_2))); case 3: return(new Color(printer.Settings.GetValue(SettingsKey.material_color_3))); } } return((materialIndex == -1) ? unassignedColor : ColorF.FromHSL(materialIndex / 10.0, .99, .49).ToColor()); }
public static Color Color(int materialIndex) { return(ColorF.FromHSL(Math.Max(materialIndex, 0) / 10.0, .99, .49).ToColor()); }
/// <summary> /// Get the color for a given extruder, falling back to the supplied color on -1 (unassigned) /// </summary> /// <param name="materialIndex">The extruder/material index to resolve</param> /// <param name="unassignedColor">The color to use when the extruder/material has not been assigned</param> /// <returns>The color for the given extruder</returns> public static Color Color(int materialIndex, Color unassignedColor) { return((materialIndex == -1) ? unassignedColor : ColorF.FromHSL(materialIndex / 10.0, .99, .49).ToColor()); }