protected virtual void SetColour(Point point) { double dx; double dy; double angle; double distance; double saturation; Padding padding; HSLColour newColour; padding = this.Padding; dx = Math.Abs(point.X - _centerPoint.X - padding.Left); dy = Math.Abs(point.Y - _centerPoint.Y - padding.Top); angle = Math.Atan(dy / dx) / Math.PI * 180; distance = Math.Pow(Math.Pow(dx, 2) + Math.Pow(dy, 2), 0.5); saturation = distance / _radius; if (point.X < _centerPoint.X) { angle = 180 - angle; } if (point.Y > _centerPoint.Y) { angle = 360 - angle; } newColour = new HSLColour(angle, saturation, 0.5); if (_hslColour != newColour) { _lockUpdates = true; this.HSLColour = newColour; this.Colour = _hslColour.ToRgbColour(); _lockUpdates = false; } }
private Bitmap DrawColourBitmap() { const int width = 5; const int height = 100; double h = _h; double s = _s; var bmp = new Bitmap(width, height); for (int y = 0; y < height; ++y) { double l = height - y; Color colour = new HSLColour(h, s, l).ToColour(); for (int x = 0; x < width; ++x) { bmp.SetPixel(x, y, colour); } } return(bmp); }
private void UpdateColours() { var deltaHue = hueBar.Value; var deltaSat = 2.0 / (saturationBar.Maximum - saturationBar.Minimum) * saturationBar.Value; var deltaLight = 2.0 / (lightnessBar.Maximum - lightnessBar.Minimum) * lightnessBar.Value; var enumValues = Enum.GetValues(typeof(ColourTableGroup)); foreach (ColourTableGroup colourTableGroup in enumValues) { if (_initialColourTable[colourTableGroup] == Color.Empty) { continue; } HSLColour hslColour = HSLColour.FromColour(_initialColourTable[colourTableGroup]); _colourTable[colourTableGroup] = new HSLColour(hslColour.Alpha, hslColour.Hue + deltaHue, hslColour.Saturation + deltaSat, hslColour.Luminosity + deltaLight).ToColour(); } MainForm.Renderer.RefreshToolStrips(); }
protected void PaintColour(PaintEventArgs e, HSLColour colour) { this.PaintColour(e, colour, false); }
private Color SetHue(Color baseColour, double hueValue) { HSLColour hslColour = new HSLColour(hue: hueValue * 240, saturation: 240, luminosity: 240); return(hslColour); }
/// <summary> /// Change handler for editing components. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void ValueChangedHandler(object sender, EventArgs e) { if (!this.LockUpdates) { bool useHsl; bool useRgb; bool useNamed; useHsl = false; useRgb = false; useNamed = false; this.LockUpdates = true; if (sender == hexTextBox) { string text; int namedIndex; text = hexTextBox.Text; if (text.StartsWith("#")) { text = text.Substring(1); } if (hexTextBox.Items.Count == 0) { this.FillNamedColours(); } namedIndex = hexTextBox.FindStringExact(text); if (namedIndex != -1 || text.Length == 6 || text.Length == 8) { try { Color color; color = namedIndex != -1 ? Color.FromName(text) : ColorTranslator.FromHtml("#" + text); aNumericUpDown.Value = color.A; rNumericUpDown.Value = color.R; bNumericUpDown.Value = color.B; gNumericUpDown.Value = color.G; useRgb = true; } // ReSharper disable EmptyGeneralCatchClause catch { } // ReSharper restore EmptyGeneralCatchClause } else { useNamed = true; } } else if (sender == aColourBar || sender == rColourBar || sender == gColourBar || sender == bColourBar) { aNumericUpDown.Value = (int)aColourBar.Value; rNumericUpDown.Value = (int)rColourBar.Value; gNumericUpDown.Value = (int)gColourBar.Value; bNumericUpDown.Value = (int)bColourBar.Value; useRgb = true; } else if (sender == aNumericUpDown || sender == rNumericUpDown || sender == gNumericUpDown || sender == bNumericUpDown) { useRgb = true; } else if (sender == hColourBar || sender == lColourBar || sender == sColourBar) { hNumericUpDown.Value = (int)hColourBar.Value; sNumericUpDown.Value = (int)sColourBar.Value; lNumericUpDown.Value = (int)lColourBar.Value; useHsl = true; } else if (sender == hNumericUpDown || sender == sNumericUpDown || sender == lNumericUpDown) { useHsl = true; } if (useRgb || useNamed) { Color colour; colour = useNamed ? Color.FromName(hexTextBox.Text) : Color.FromArgb((int)aNumericUpDown.Value, (int)rNumericUpDown.Value, (int)gNumericUpDown.Value, (int)bNumericUpDown.Value); this.Colour = colour; this.HSLColour = new HSLColour(colour); } else if (useHsl) { HSLColour colour; colour = new HSLColour((int)aNumericUpDown.Value, (double)hNumericUpDown.Value, (double)sNumericUpDown.Value / 100, (double)lNumericUpDown.Value / 100); this.HSLColour = colour; this.Colour = colour.ToRgbColour(); } this.LockUpdates = false; this.UpdateFields(true); } }
private void SetColour(HSLColour colour) { SetColour(colour.ToRGBColour()); }
public static HSLColourAssertions Should(this HSLColour value) => new HSLColourAssertions(value);