Beispiel #1
0
        private void BuildWheel()
        {
            var width  = 1024;
            var height = width;
            var cx     = width / 2;
            var cy     = height / 2;
            var colors = new int[width * height];
            var gray   = Colors.Gray.ToBgr32();

            for (int index = 0; index < colors.Length; index++)
            {
                colors[index] = gray;
            }

            var radius        = cx;
            var radiusSquared = radius * radius;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    var x = j - cx;
                    var y = i - cy;
                    var distanceSquared = (double)x * x + y * y;
                    if (distanceSquared <= radiusSquared)                              // In circle
                    {
                        var h   = Math.Atan2(x, y).ToDegrees() + 180.0d;               // Angle
                        var s   = 1.0d;
                        var l   = (1.0d - ((1.0d / radiusSquared) * distanceSquared)); // 1 - (distance normalized)
                        var hsl = new HSL((float)h, (float)s, (float)l);
                        var rgb = RGB.FromHsl(hsl.H, hsl.S, hsl.L);
                        colors[i * width + j] = rgb.R << 16 | rgb.G << 8 | rgb.B;
                    }
                }
            }
            var bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);

            bitmap.WritePixels(new Int32Rect(0, 0, width, height), colors, width * 4, 0);
            image.Source = bitmap;
        }
Beispiel #2
0
 public bool Equals(HSL other)
 {
     return(other._h.Equals(_h) && other._l.Equals(_l) &&
            other._s.Equals(_s));
 }