예제 #1
0
        //Draw a circle on any 3d axis
        public void DrawCircle2DAnyAxis(GridContext bgc, PenTwist ptt, int x0, int y0, int z, int radius)
        {
            int sx = radius, sy = 0;
            int radiusError = 1 - sx;

            while (sx >= sy)
            {
                DrawAxisPen(bgc, ptt, sx + x0, sy + y0, z);
                DrawAxisPen(bgc, ptt, sy + x0, sx + y0, z);
                DrawAxisPen(bgc, ptt, -sx + x0, sy + y0, z);
                DrawAxisPen(bgc, ptt, -sy + x0, sx + y0, z);
                DrawAxisPen(bgc, ptt, -sx + x0, -sy + y0, z);
                DrawAxisPen(bgc, ptt, -sy + x0, -sx + y0, z);
                DrawAxisPen(bgc, ptt, sx + x0, -sy + y0, z);
                DrawAxisPen(bgc, ptt, sy + x0, -sx + y0, z);

                sy++;
                if (radiusError < 0)
                {
                    radiusError += 2 * sy + 1;
                }
                else
                {
                    sx--;
                    radiusError += 2 * (sy - sx + 1);
                }
            }
        }
예제 #2
0
        //Draw Polygon to Grid
        public void DrawPolygon(GridContext bgc, PenTwist twistType, int x, int y, int z, int radius, int sides)
        {
            double angleSize = 360.0 / sides;

            for (int i = 0; i < sides; i++)
            {
                double vx1    = radius;
                double vy1    = 0;
                var    angle1 = (int)(i * angleSize);
                MathTrigonometry.RotateZ(-angle1, ref vx1, ref vy1);

                double vx2    = radius;
                double vy2    = 0;
                var    angle2 = (int)((i + 1) * angleSize);

                MathTrigonometry.RotateZ(-angle2, ref vx2, ref vy2);

                if (i == sides - 1) //connect last segment
                {
                    vx2 = radius;
                    vy2 = 0;
                }
                DrawAxisLine2D(bgc, twistType, x + (int)vx1, y + (int)vy1, x + (int)vx2, y + (int)vy2, z);
            }
        }
예제 #3
0
        //Draw an arbitrary shape at XYZ
        public void DrawShape(GridContext bgc, PenTwist twistType, int type, int x, int y, int z, int scale)
        {
            switch (type)
            {
            case 0: DrawPen(bgc, x, y, z); break;

            case 1: DrawLine2D(bgc, x - scale, y - scale, x + scale, y + scale, z); break;

            case 2: DrawFillRect(bgc, x - scale, y - scale, z - scale, x + scale, y + scale, z + scale); break;

            case 3: DrawPolygon(bgc, twistType, x, y, z, scale, 3); break;

            case 4: DrawPolygon(bgc, twistType, x, y, z, scale, 4); break;

            case 5: DrawPolygon(bgc, twistType, x, y, z, scale, 5); break;

            case 6: DrawPolygon(bgc, twistType, x, y, z, scale, 6); break;

            case 7: DrawPolygon(bgc, twistType, x, y, z, scale, 7); break;

            case 8: DrawPolygon(bgc, twistType, x, y, z, scale, 8); break;

            case 9: DrawCircle2DAnyAxis(bgc, twistType, x, y, z, scale); break;
            }
        }
예제 #4
0
        //Draw filled circle in two dimensions
        public void DrawFillCircle2D(GridContext bgc, PenTwist ptt, int x1, int y1, int z, int radius)
        {
            int sx = radius, sy = 0;
            int radiusError = 1 - sx;

            while (sx >= sy)
            {
                DrawHorizontalLine(bgc, ptt, sx + x1, -sx + x1, sy + y1, z);
                DrawHorizontalLine(bgc, ptt, sy + x1, -sy + x1, sx + y1, z);

                DrawHorizontalLine(bgc, ptt, sx + x1, -sx + x1, -sy + y1, z);
                DrawHorizontalLine(bgc, ptt, sy + x1, -sy + x1, -sx + y1, z);

                sy++;
                if (radiusError < 0)
                {
                    radiusError += 2 * sy + 1;
                }
                else
                {
                    sx--;
                    radiusError += 2 * (sy - sx + 1);
                }
            }
        }
예제 #5
0
        //Draw an arbitrary letter to Grid
        public void DrawLetter(GridContext bgc, PenTwist twistType, int x, int y, int z, int letter, bool flip)
        {
            string[] font = GetCharacterFont((char)letter);
            if (font == null)
            {
                return;
            }

            for (int sy = 0; sy < 5; sy++)
            {
                for (int sx = 0; sx < 5; sx++)
                {
                    if (font[sy][sx] == '#')
                    {
                        if (flip)
                        {
                            DrawAxisPen(bgc, twistType, x + sx, y + (4 - sy), z);
                        }
                        else
                        {
                            DrawAxisPen(bgc, twistType, x + sx, y + sy, z);
                        }
                    }
                }
            }
        }
 //Draw a horizontal line to Grid
 public void DrawHorizontalLine(GridContext bgc, PenTwist ptt, int x1, int x2, int y, int z)
 {
     MinMax(ref x1, ref x2);
     for (int x = x1; x < x2; x++)
     {
         DrawAxisPen(bgc, ptt, x, y, z);
     }
 }
예제 #7
0
        //Draw an Arc to Grid
        public void DrawArc(GridContext bgc, PenTwist twistType, int x, int y, int z, int radius, int startAnglePercent, int stopAnglePercent)
        {
            var realStartAngle = (int)(startAnglePercent * 3.6);
            var realStopAngle  = (int)(stopAnglePercent * 3.6);

            for (int angle = realStartAngle; angle < realStopAngle; angle++)
            {
                double vx = radius;
                double vy = 0;
                MathTrigonometry.RotateZ(-angle, ref vx, ref vy);
                DrawAxisPen(bgc, twistType, x + (int)vx, y + (int)vy, z);
            }
        }
예제 #8
0
        //Re-dRect and draw a pen to Grid
        public void DrawAxisPen(GridContext bgc, PenTwist penTwist, int x, int y, int z)
        {
            if (bgc == null)
            {
                return;
            }

            switch (penTwist)
            {
            case PenTwist.XYaxis: DrawPen(bgc, x, y, z); break;

            case PenTwist.YZaxis: DrawPen(bgc, z, y, x); break;

            case PenTwist.XZaxis: DrawPen(bgc, x, z, y); break;
            }
        }
예제 #9
0
        //Draw an arbitrary 2d line along twisted axis to Grid
        public void DrawAxisLine2D(GridContext bgc, PenTwist twistType, int x1, int y1, int x2, int y2, int z)
        {
            int dx = Math.Abs(x2 - x1), sx = x1 < x2 ? 1 : -1;
            int dy = Math.Abs(y2 - y1), sy = y1 < y2 ? 1 : -1;
            int err = (dx > dy ? dx : -dy) / 2;

            for (; ;)
            {
                DrawAxisPen(bgc, twistType, x1, y1, z);
                if (x1 == x2 && y1 == y2)
                {
                    break;
                }
                int e2 = err;
                if (e2 > -dx)
                {
                    err -= dy; x1 += sx;
                }
                if (e2 < dy)
                {
                    err += dx; y1 += sy;
                }
            }
        }