Completed ShapeGenerator.cs
This commit is contained in:
parent
8342eff07e
commit
be719d379c
1 changed files with 29 additions and 5 deletions
|
|
@ -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
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue