コード例 #1
0
ファイル: ShapesArtist.cs プロジェクト: DBHeise/RoboDave
        public static void DrawShape(Graphics gfx, RectangleF area, Shapes shape, Boolean randomWithin, Boolean isfilled)
        {
            Shapes trueshape = shape;

            if (trueshape == Shapes.RandomShape)
            {
                trueshape = GetRandomShape();
            }

            RectangleF rect = area;

            if (randomWithin)
            {
                float x      = Rando.RandomFloat(area.X, area.X + area.Width);
                float y      = Rando.RandomFloat(area.Y, area.Y + area.Height);
                float width  = Rando.RandomFloat(1, area.Width);
                float height = Rando.RandomFloat(1, area.Height);
                rect = new RectangleF(x, y, width, height);
            }

            if (trueshape == Shapes.Square || trueshape == Shapes.Circle)
            {
                rect.Width  = Math.Min(rect.Width, rect.Height);
                rect.Height = rect.Width;
            }

            using (var brush = new SolidBrush(Rando.RandomColor()))
                using (var pen = new Pen(brush, Rando.RandomFloat(0.5f, 10.0f)))
                {
                    switch (trueshape)
                    {
                    case Shapes.Circle:
                    case Shapes.Ellipse:
                        DrawEllipse(gfx, brush, pen, rect, isfilled);
                        break;

                    default:
                    {
                        PointF[] points = GeneratePoints(trueshape, rect);
                        DrawPolygon(gfx, brush, pen, points, isfilled);
                    }
                    break;
                    }
                }
        }