예제 #1
0
        static Color32[] RasterizeGradient(GradientFill gradient, int width, int height)
        {
            Color32[] pixels = new Color32[width * height];

            if (gradient.Type == GradientFillType.Linear)
            {
                int pixIndex = 0;
                for (int x = 0; x < width; x++)
                {
                    pixels[pixIndex++] = SampleGradient(gradient.Stops, x / (float)(width - 1));
                }
                for (int y = 1; y < height; y++)
                {
                    Array.Copy(pixels, 0, pixels, pixIndex, width);
                    pixIndex += width;
                }
            }
            else if (gradient.Type == GradientFillType.Radial)
            {
                int pixIndex = 0;
                for (int y = 0; y < height; y++)
                {
                    float v = y / ((float)height - 1);
                    for (int x = 0; x < width; x++)
                    {
                        float u = x / ((float)width - 1);
                        pixels[pixIndex++] = SampleGradient(gradient.Stops, RadialAddress(new Vector2(u, 1.0f - v), gradient.RadialFocus));
                    }
                }
            }

            return(pixels);
        }
예제 #2
0
 static Color32[] RasterizeGradientStripe(GradientFill gradient, int width)
 {
     Color32[] pixels = new Color32[width];
     for (int x = 0; x < width; ++x)
     {
         float u = x / ((float)width - 1);
         pixels[x] = SampleGradient(gradient.Stops, u);
     }
     return(pixels);
 }