public void ToRGBWithAccentReturnsCorrectValues() { var accent = new Color.HSL(36.6, 0.928, 0.488); var rgb = accent.ToRGB(); Assert.AreEqual(new Color.RGB(240, 150, 9), rgb); }
public void ToRGBWithWhiteReturnsCorrectValues() { var accent = new Color.HSL(0, 0, 1); var rgb = accent.ToRGB(); Assert.AreEqual(new Color.RGB(255, 255, 255), rgb); }
public void EqualsWithDifferentColoursReturnsFalse() { var c1 = new Color.HSL(315.3, 0.462, 0.467); var c2 = new Color.HSL(315.5, 0.462, 0.467); Assert.IsFalse(c1.Equals(c2)); }
public void ToHSVWithAccentReturnsCorrectValues() { var accent = new Color.HSL(36.6, 0.928, 0.488); var hsv = accent.ToHSV(); Assert.AreEqual(new Color.HSV(36.6, 0.963, 0.941), hsv); }
public void EqualsWithSameColoursReturnsTrue() { var c1 = new Color.HSL(315.3, 0.462, 0.467); var c2 = new Color.HSL(315.3, 0.462, 0.467); Assert.IsTrue(c1.Equals(c2)); }
public void ToRGBWithBlackReturnsCorrectValues() { var accent = new Color.HSL(0, 0, 0); var rgb = accent.ToRGB(); Assert.AreEqual(new Color.RGB(0, 0, 0), rgb); }
public void ToHSVWithBlackReturnsCorrectValues() { var accent = new Color.HSL(0, 0, 0); var hsv = accent.ToHSV(); Assert.AreEqual(new Color.HSV(0, 0, 0), hsv); }
/// <summary> /// Applies the rainbow effect on the LED strip /// </summary> public static void CalcRainbow(double Saturation, double Lightness) { decimal HSLstep = 360M / LEDs.Count; for (int i = 0; i < LEDs.Count; i++) { //The HSL ColorSpace is WAY better do calculate this type of effect LEDs[i] = new Color.HSL((double)Math.Ceiling(i * HSLstep), Saturation, Lightness); } }
private void UpdateColor() { var hsl = new Color.HSL(currentHue, currentSaturation, currentLuminosity); var rgb = hsl.ToRGB(); InputPanel.Background = new SolidColorBrush(rgb.ToSystemColor(255)); Description.Text = rgb.ToHexString(); Description.Foreground = new SolidColorBrush(hsl.L < 0.5d ? Windows.UI.Colors.White : Windows.UI.Colors.Black); }
/// <summary> /// Initializes with a new Random color /// </summary> public LEDBulb() { Random random = new Random(); //Generating a random color via the HSL colorspace and then convert it to //Tradicional RGB, this makes the software generate randomized, yet saturated colors var BaseColor = new Color.HSL(random.Next(0, 360), 1, .5).ToRGB(); this.r = BaseColor.R; this.g = BaseColor.G; this.b = BaseColor.B; }
private void OnLoaded(object sender, RoutedEventArgs e) { var random = new Random(); currentHue = random.Next(0, 360); currentLuminosity = random.NextDouble(); UpdateColor(); Observable.FromEventPattern <PointerRoutedEventArgs>(InputPanel, "PointerPressed") .Subscribe(ev => Description.Visibility = Visibility.Collapsed); Observable.FromEventPattern <PointerRoutedEventArgs>(InputPanel, "PointerReleased") .Subscribe(ev => Description.Visibility = Visibility.Visible); Observable.FromEventPattern <PointerRoutedEventArgs>(InputPanel, "PointerMoved") .Where(ev => !ev.EventArgs.Handled) .Select(ev => ev.EventArgs.GetCurrentPoint(InputPanel)) .Select(p => new { Width = p.Position.X / InputPanel.ActualWidth, Height = p.Position.Y / InputPanel.ActualHeight }) .Subscribe(p => { currentHue = p.Width * 360.0d; currentLuminosity = p.Height; UpdateColor(); }); Observable.FromEventPattern <RangeBaseValueChangedEventArgs>(SaturationSlider, "ValueChanged") .Select(ev => ev.EventArgs.NewValue) .Subscribe(s => { currentSaturation = s; UpdateColor(); }); Observable.FromEventPattern <PointerRoutedEventArgs>(InputPanel, "PointerReleased") .Where(ev => ViewModel.Colors.Count < 5) .Subscribe(ev => { var hsl = new Color.HSL(currentHue, currentSaturation, currentLuminosity); var rgb = hsl.ToRGB(); ViewModel.Add(rgb.ToSystemColor(255)); }); }
/// <summary> /// コンストラクタ /// </summary> public ColorEdit() { InitializeComponent(); //*** プレビュー子画面を表示 ***// FmPreview.Show(); //*** 色相環画像生成 ***// BmpHue = new Bitmap(picCondHue.Width - 2, picCondHue.Height - 2); byte[] pix = new byte[BmpHue.Width * BmpHue.Height * 4]; BitmapData bmpData = BmpHue.LockBits( new Rectangle(0, 0, BmpHue.Width, BmpHue.Height) , ImageLockMode.ReadOnly , BmpHue.PixelFormat ); double x, y, r; Color.HSL hsl = new Color.HSL(); for (int py = 0; py < BmpHue.Height; ++py) { for (int px = 0, s = py * bmpData.Stride; px < BmpHue.Width; ++px, s += 4) { x = 2.0 * px / BmpHue.Width - 1.0; y = 1.0 - 2.0 * py / BmpHue.Height; r = Math.Sqrt(x * x + y * y); if (r >= 0.75 && r <= 0.9) { hsl.H = (int)(45 * Math.Atan2(y, x) / Math.Atan(1.0)); hsl.S = 100; hsl.L = 50; hsl.A = 255; Color.HSLtoRGB(ref hsl, ref pix, ref s); } } } Marshal.Copy(pix, 0, bmpData.Scan0, pix.Length); BmpHue.UnlockBits(bmpData); //*** 設定の読み込み ***// InitSetting(); //*** 値の反映 ***// ValueChenged(); }
protected SingleColorSchemeEditorViewModelBase(IWindowManager windowManager) : base(windowManager) { var random = new Random(); var hue = random.Next(0, 360); var hsl = new Color.HSL(hue, 0.5d, 0.5d); CurrentColor = new ColourViewModel { Color = hsl.ToRGB().ToSystemColor(255) }; CurrentHue = hsl.H; CurrentSaturation = hsl.S; CurrentLuminosity = hsl.L; }
public VertexPosColor(Vector3 position, Color.HSL color) : this(position, color.ToVulkanCore()) { }
/// <summary> /// HSL色空間の描画 /// </summary> /// <param name="pictH"></param> /// <param name="pictS"></param> /// <param name="pictL"></param> /// <param name="param"></param> private void DrawHSL(PictureBox pictH, PictureBox pictS, PictureBox pictL, Color.Param param) { Pen penNorm = new Pen(System.Drawing.Color.Black, 1.0f); Pen penBold = new Pen(System.Drawing.Color.Black, 4.0f); Color.HSL hsl = new Color.HSL(); //*** 色相環の描画 ***// Bitmap bmpHue = new Bitmap(BmpHue.Width, BmpHue.Height); Graphics gHue = Graphics.FromImage(bmpHue); RectangleF rectHue = new RectangleF(0.0f, 0.0f, bmpHue.Width, bmpHue.Height); double th = -Math.Atan(1.0) * param.H / 45.0; float ax = (float)(bmpHue.Width * Math.Cos(th) / 2.0); float ay = (float)(bmpHue.Height * Math.Sin(th) / 2.0); float bx = 0.75f * ax + bmpHue.Width / 2.0f; float by = 0.75f * ay + bmpHue.Height / 2.0f; ax += bmpHue.Width / 2.0f; ay += bmpHue.Height / 2.0f; gHue.DrawImage(BmpHue, 0, 0); gHue.DrawArc(penBold, rectHue, -param.H, param.HWidth); gHue.DrawArc(penBold, rectHue, -param.H - param.HWidth, param.HWidth); gHue.DrawLine(penNorm, new PointF(ax, ay), new PointF(bx, by)); pictH.Image = bmpHue; //*** 彩度と明度の描画 ***// Bitmap bmpS = new Bitmap(pictS.Width, pictS.Height); Bitmap bmpL = new Bitmap(pictL.Width, pictL.Height); byte[] pixS = new byte[bmpS.Width * bmpS.Height * 4]; byte[] pixL = new byte[bmpL.Width * bmpL.Height * 4]; BitmapData bmpSData = bmpS.LockBits( new Rectangle(0, 0, bmpS.Width, bmpS.Height) , ImageLockMode.ReadOnly , bmpS.PixelFormat ); BitmapData bmpLData = bmpL.LockBits( new Rectangle(0, 0, bmpL.Width, bmpL.Height) , ImageLockMode.ReadOnly , bmpL.PixelFormat ); double k = 100.0 / bmpS.Width; for (int px = 0, s = 0; px < bmpS.Width; ++px, s += 4) { hsl.H = param.H; hsl.S = (int)(k * px); hsl.L = 50; hsl.A = 255; Color.HSLtoRGB(ref hsl, ref pixS, ref s); hsl.H = param.H; hsl.S = param.SMax; hsl.L = (int)(k * px); hsl.A = 255; Color.HSLtoRGB(ref hsl, ref pixL, ref s); } for (int py = 0, s = 0; py < bmpS.Height; ++py, s += bmpSData.Stride) { Array.Copy(pixS, 0, pixS, s, bmpSData.Stride); Array.Copy(pixL, 0, pixL, s, bmpSData.Stride); } Marshal.Copy(pixS, 0, bmpSData.Scan0, pixS.Length); Marshal.Copy(pixL, 0, bmpLData.Scan0, pixL.Length); bmpS.UnlockBits(bmpSData); bmpL.UnlockBits(bmpLData); pictS.Image = bmpS; pictL.Image = bmpL; }
public void ShiftHueWraps360() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(0, 0.5, 0.5), hsl.ShiftHue(270)); }
public void ShiftLightnessCeiling() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(90, 0.5, 1.0), hsl.ShiftLightness(0.8)); }
/// <summary> /// Convert Spectrum.Color.HSL to VulkanCore.ColorF4 /// </summary> /// <param name="color"></param> /// <returns></returns> public static ColorF4 ToVulkanCore(this Color.HSL color) { return(color.ToRGB().ToVulkanCore()); }
public void ShiftLightnessFloor() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(90, 0.5, 0.0), hsl.ShiftLightness(-0.8)); }
public VertexPosTexColor(Vector3 position, Vector2 texCoord, Color.HSL color) : this(position, texCoord, color.ToVulkanCore()) { }
public void ShiftHueAddsToHue() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(120, 0.5, 0.5), hsl.ShiftHue(30)); }
public void ShiftHueWraps0() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(330, 0.5, 0.5), hsl.ShiftHue(-120)); }
public void ShiftLightnessAddsToLightness() { var hsl = new Color.HSL(90, 0.5, 0.5); Assert.AreEqual(new Color.HSL(90, 0.5, 0.7), hsl.ShiftLightness(0.2)); }