Пример #1
0
        private static void Line(Texture2D texture, int x0, int y0, int x1, int y1, Color color)
        {
            int width = texture.width;
            int height = texture.height;

            bool isSteep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
            if (isSteep)
            {
                Swap(ref x0, ref y0);
                Swap(ref x1, ref y1);
            }
            if (x0 > x1)
            {
                Swap(ref x0, ref x1);
                Swap(ref y0, ref y1);
            }

            int deltax = x1 - x0;
            int deltay = Math.Abs(y1 - y0);

            int error = deltax / 2;
            int ystep;
            int y = y0;

            if (y0 < y1)
                ystep = 1;
            else
                ystep = -1;

            for (int x = x0; x < x1; x++)
            {
                if (isSteep)
                    texture.DrawPixel(y, x, width, height, color);
                else
                    texture.DrawPixel(x, y, width, height, color);

                error = error - deltay;
                if (error < 0)
                {
                    y = y + ystep;
                    error = error + deltax;
                }
            }
        }
Пример #2
0
 private static void PlotCircle(Texture2D texture, int cx, int x, int cy, int y, Color color)
 {
     texture.DrawPixel(cx + x, cy + y, color); // Point in octant 1...
     texture.DrawPixel(cy + x, cx + y, color);
     texture.DrawPixel(-cx + x, cy + y, color);
     texture.DrawPixel(-cy + x, cx + y, color);
     texture.DrawPixel(-cx + x, -cy + y, color);
     texture.DrawPixel(-cy + x, -cx + y, color);
     texture.DrawPixel(cx + x, -cy + y, color);
     texture.DrawPixel(cy + x, -cx + y, color); // ... point in octant 8
 }