private void setHS(Point position) { double h = (double)(position.X) / (double)(image2.Width); double s = (double)(position.Y) / (double)(image2.Height); h = Math.Max(0.0, Math.Min(1.0, h)); s = Math.Max(0.0, Math.Min(1.0, s)); _HSLColour._H = h; _HSLColour._S = s; _Colour = _HSLColour.GetColour(); RenderSwatches(); }
private void RenderHS() { int width = (int)image2.Width; int height = (int)image2.Height; byte[] pixels = new byte[4 * height * width]; WriteableBitmap writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null); int p = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float floatx = (float)x / (float)(width - 1); float floaty = (float)y / (float)(height - 1); HSLColour hslcol = new HSLColour(floatx, floaty, _HSLColour._L); Colour col = hslcol.GetColour(); col.Clamp(0, 1); pixels[p * 4] = (byte)(col._Blue * 255.99f); pixels[p * 4 + 1] = (byte)(col._Green * 255.99f); pixels[p * 4 + 2] = (byte)(col._Red * 255.99f); pixels[p * 4 + 3] = 255; p++; } } Int32Rect rect = new Int32Rect(0, 0, width, height); writeableBitmap.WritePixels(rect, pixels, width * 4, (int)0); image2.Source = writeableBitmap; }
private void RenderSwatches() { HSLColour col = new HSLColour(1, 0.5, 0.5); Colour bob = col.GetColour(); RenderHS(); RenderL(); RenderCol(); }