示例#1
0
 /// <summary>
 /// Draws a line on the IPixels between two points.
 /// </summary>
 /// <param name="pixels">The IPixels to draw on.</param>
 /// <param name="rgb">The color of the line.</param>
 public static void DrawLine(IPixels pixels,
     int x0, int y0, int x1, int y1, int rgb)
 {
     rgb = rgb & 0xFFFFFF;
     //Bresenham line algorithm implementation
     int sx = (x0 < x1 ? 1 : -1), sy = (y0 < y1 ? 1 : -1);
     int dx = Math.Abs(x1 - x0), dy = Math.Abs(y1 - y0);
     int err = dx - dy;
     while (true)
     {
         //set pixel
         pixels[y0, x0] = pixels[y0, x0] & (0xFF << 24) | rgb;
         //check for break
         if (x0 == x1 && y0 == y1) break;
         //advance x0 and y0
         int err2 = 2 * err;
         if (err2 > -dy)
         {
             err -= dy;
             x0 += sx;
         }
         if (err2 < dx)
         {
             err += dx;
             y0 += sy;
         }
     }
 }
示例#2
0
 /// <summary>
 /// Applies a Shader to the IPixels.
 /// </summary>
 /// <param name="pixels">The IPixels to shade.</param>
 /// <param name="shader">The Shader to apply to the pixels.</param>
 public static void Apply(IPixels pixels, Shader shader)
 {
     for (int row = 0; row < pixels.Height; row++)
     {
         for (int col = 0; col < pixels.Width; col++)
         {
             pixels[row, col] = shader(pixels[row, col]);
         }
     }
 }
示例#3
0
 /// <summary>
 /// Constructs a new Selection.
 /// </summary>
 /// <param name="pixels">The IPixels from which
 /// pixels should be selected.</param>
 /// <param name="rect">The Rectangle of pixels to use.</param>
 public Selection(IPixels pixels, PixRect rect)
 {
     this.pixels = pixels;
     this.rect = rect;
 }
示例#4
0
 /// <summary>
 /// Draws a filled rectangle.
 /// </summary>
 /// <param name="pixels">The IPixels to draw on.</param>
 /// <param name="rect">The rectangle to draw.</param>
 /// <param name="rgb">The color to use.</param>
 public static void FillRect(IPixels pixels, PixRect rect, int rgb)
 {
     Selection selection = new Selection(pixels, rect);
     Shaders.Apply(selection, Shaders.SolidColor(rgb));
 }