コード例 #1
0
        //ToDo: fix drawline algorythm
        public static void DrawLine(this GraphicContext gc, Point p1, Point p2, Color color)
        {
            uint dx, dy, p, x = 0, y = 0, x0, y0, x1, y1;

            x0 = p1.X;
            y0 = p1.Y;
            x1 = p2.X;
            y1 = p2.Y;

            dx = x1 - x0;
            dy = y1 - y0;
            p  = 2 * dy - dx;

            while (x < x1)
            {
                if (p >= 0)
                {
                    gc.SetPixel(color, new Point(x, y));
                    y = y + 1;
                    p = p + 2 * dy - 2 * dx;
                }
                else
                {
                    gc.SetPixel(color, new Point(x, y));
                    p = p + 2 * dy;
                }
                x = x + 1;
            }
        }
コード例 #2
0
        public static void DrawCircle(this GraphicContext gc, Point loc, uint radius, Color color)
        {
            uint x   = radius;
            uint y   = 0;
            uint err = 0;

            while (x >= y)
            {
                gc.SetPixel(color, new Point(loc.X + x, loc.Y + y));
                gc.SetPixel(color, new Point(loc.X + y, loc.Y + x));

                gc.SetPixel(color, new Point(loc.X - y, loc.Y + x));
                gc.SetPixel(color, new Point(loc.X - x, loc.Y + y));

                gc.SetPixel(color, new Point(loc.X - x, loc.Y - y));
                gc.SetPixel(color, new Point(loc.X - y, loc.Y - x));

                gc.SetPixel(color, new Point(loc.X + y, loc.Y - x));
                gc.SetPixel(color, new Point(loc.X + x, loc.Y - y));

                if (err <= 0)
                {
                    y   = y + 1;
                    err = err + 2 * x + 1;
                }
                if (err > 0)
                {
                    x   = x - 1;
                    err = err - 2 * x + 1;
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Draws an filled Rectangle on the Display
 /// </summary>
 /// <param name="rec">The Location and Bounds of the Rectangle</param>
 /// <param name="color">The color of the Rectangle</param>
 public static void FillRectangle(this GraphicContext gc, Rectangle rec, Color color)
 {
     for (int x = 0; x < rec.Size.Width; x++)
     {
         for (int y = 0; y < rec.Size.Height; y++)
         {
             gc.SetPixel(color, rec.Location + new Point(x, y));
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Draw An Image on the Screen
 /// </summary>
 /// <param name="gc">The GraphicContext to draw</param>
 /// <param name="location">The Location to start Drawing</param>
 /// <param name="img">The Image to draw</param>
 public static void DrawImage(this GraphicContext gc, Point location, Image img)
 {
     for (uint x1 = 0; x1 < img.Width; x1++)
     {
         for (uint y1 = 0; y1 < img.Height; y1++)
         {
             gc.SetPixel(img.GetPixel(x1, y1), new Point(location.X + x1, location.Y + y1));
         }
     }
 }
コード例 #5
0
        public static void FillTriangle(this GraphicContext gc, Point loc, Point v0, Point v1, Point v2, Color c)
        {
            var scanBuffer = new List <MinMaxPair>();

            for (int i = 0; i < gc.Size.Height; i++)
            {
                scanBuffer.Add(new MinMaxPair(0, 0));
            }

            Point minYVert = v0;
            Point midYVert = v1;
            Point maxYVert = v2;

            if (maxYVert.Y < midYVert.Y)
            {
                Point temp = maxYVert;
                maxYVert = midYVert;
                midYVert = temp;
            }

            if (midYVert.Y < minYVert.Y)
            {
                Point temp = midYVert;
                midYVert = minYVert;
                minYVert = temp;
            }

            if (maxYVert.Y < midYVert.Y)
            {
                Point temp = maxYVert;
                maxYVert = midYVert;
                midYVert = temp;
            }

            float area       = minYVert.TriangleArea(maxYVert, midYVert);
            int   handedness = area >= 0 ? 1 : 0;

            ScanConvertTriangle(gc, scanBuffer, minYVert, midYVert, maxYVert, handedness);

            for (var j = 0; j < scanBuffer.Count; j++)
            {
                var minMaxPair = scanBuffer[j];
                for (int i = minMaxPair.Min; i < minMaxPair.Max; i++)
                {
                    gc.SetPixel(c, new Point((uint)(loc.X + i), (uint)(loc.Y + j)));
                }
            }
        }