コード例 #1
0
            /// <summary>
            /// Fills the bottom left quadrent with 3 horizental bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid).
            /// </summary>
            /// <param name="pixels"></param>
            private static void TransparentGradients(PixelAccessor <TPixel> pixels)
            {
                // topLeft
                int left   = 0;
                int right  = pixels.Width / 2;
                int top    = pixels.Height / 2;
                int bottom = pixels.Height;
                int height = (int)Math.Ceiling(pixels.Height / 6f);

                Vector4 red   = Rgba32.Red.ToVector4();   // use real color so we can see har it translates in the test pattern
                Vector4 green = Rgba32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern
                Vector4 blue  = Rgba32.Blue.ToVector4();  // use real color so we can see har it translates in the test pattern

                TPixel c = default(TPixel);

                for (int x = left; x < right; x++)
                {
                    blue.W = red.W = green.W = (float)x / (float)right;

                    c.PackFromVector4(red);
                    int topBand = top;
                    for (int y = topBand; y < top + height; y++)
                    {
                        pixels[x, y] = c;
                    }
                    topBand = topBand + height;
                    c.PackFromVector4(green);
                    for (int y = topBand; y < topBand + height; y++)
                    {
                        pixels[x, y] = c;
                    }
                    topBand = topBand + height;
                    c.PackFromVector4(blue);
                    for (int y = topBand; y < bottom; y++)
                    {
                        pixels[x, y] = c;
                    }
                }
            }
コード例 #2
0
            /// <summary>
            /// Fills the bottom right quadrant with all the colors producable by converting itterating over a uint and unpacking it.
            /// A better algorithm could be used but it works
            /// </summary>
            /// <param name="pixels"></param>
            private static void Rainbow(PixelAccessor <TPixel> pixels)
            {
                int left   = pixels.Width / 2;
                int right  = pixels.Width;
                int top    = pixels.Height / 2;
                int bottom = pixels.Height;

                int    pixelCount    = left * top;
                uint   stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
                TPixel c             = default(TPixel);
                Rgba32 t             = new Rgba32(0);

                for (int x = left; x < right; x++)
                {
                    for (int y = top; y < bottom; y++)
                    {
                        t.PackedValue += stepsPerPixel;
                        Vector4 v = t.ToVector4();
                        //v.W = (x - left) / (float)left;
                        c.PackFromVector4(v);
                        pixels[x, y] = c;
                    }
                }
            }