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;
@ -16,6 +18,18 @@ public sealed class ShapeGenerator
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
/// </summary> /// </summary>
@ -46,9 +60,19 @@ public sealed class ShapeGenerator
_nextShape = MinShapeIdx; _nextShape = MinShapeIdx;
} }
// TODO var randomSize = new Point(_random.NextDouble() * _maxX, _random.NextDouble() * _maxY);
return null!; var randomThickness = _random.NextDouble() * 3 + 1;
} var randomColor = colors[_random.Next(colors.Length)];
// TODO 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)
};
return generatedShape;
}
} }