From be719d379c4bc610b3d274c59b96a39c1a24f24c Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Sun, 16 Mar 2025 23:23:20 +0100 Subject: [PATCH] Completed ShapeGenerator.cs --- Shapes/ShapeGenerator.cs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Shapes/ShapeGenerator.cs b/Shapes/ShapeGenerator.cs index 50494c6..0a7664d 100644 --- a/Shapes/ShapeGenerator.cs +++ b/Shapes/ShapeGenerator.cs @@ -1,5 +1,7 @@ using System.Diagnostics; +using System.Numerics; using Avalonia; +using Avalonia.Media; using Shapes.Shapes; namespace Shapes; @@ -15,6 +17,18 @@ public sealed class ShapeGenerator private readonly double _maxY; private readonly Random _random; private int _nextShape; + + private static readonly IBrush[] colors = + { + Brushes.Blue, + Brushes.Cyan, + Brushes.DarkGreen, + Brushes.Firebrick, + Brushes.Lime, + Brushes.Orange, + Brushes.Plum, + Brushes.Yellow + }; /// /// Creates a new generator which will create random shapes within the canvas area @@ -45,10 +59,20 @@ public sealed class ShapeGenerator { _nextShape = MinShapeIdx; } + + var randomSize = new Point(_random.NextDouble() * _maxX, _random.NextDouble() * _maxY); + var randomThickness = _random.NextDouble() * 3 + 1; + var randomColor = colors[_random.Next(colors.Length)]; + + Shape generatedShape = shape switch + { + 1 => new Circle(atLocation, randomSize, randomThickness, randomColor, randomColor), + 2 => new Rectangle(atLocation, randomSize, randomThickness, randomColor, randomColor), + 3 => new Square(atLocation, randomSize, randomThickness, randomColor, randomColor), + 4 => new Triangle(atLocation, randomSize, randomThickness, randomColor, randomColor), + _ => new Square(atLocation, randomSize, randomThickness, randomColor, randomColor) + }; - // TODO - return null!; + return generatedShape; } - - // TODO -} +} \ No newline at end of file