Completed ShapeGenerator.cs

This commit is contained in:
MarcUs7i 2025-03-16 23:23:20 +01:00
parent 8342eff07e
commit be719d379c

View file

@ -1,5 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Numerics;
using Avalonia; using Avalonia;
using Avalonia.Media;
using Shapes.Shapes; using Shapes.Shapes;
namespace Shapes; namespace Shapes;
@ -15,6 +17,18 @@ public sealed class ShapeGenerator
private readonly double _maxY; private readonly double _maxY;
private readonly Random _random; private readonly Random _random;
private int _nextShape; private int _nextShape;
private static readonly IBrush[] colors =
{
Brushes.Blue,
Brushes.Cyan,
Brushes.DarkGreen,
Brushes.Firebrick,
Brushes.Lime,
Brushes.Orange,
Brushes.Plum,
Brushes.Yellow
};
/// <summary> /// <summary>
/// Creates a new generator which will create random shapes within the canvas area /// Creates a new generator which will create random shapes within the canvas area
@ -45,10 +59,20 @@ public sealed class ShapeGenerator
{ {
_nextShape = MinShapeIdx; _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 generatedShape;
return null!;
} }
}
// TODO
}