Terminaux also provides a wide assortment of classes that allow you to render different geometric shapes to the console easily. You can select one of the following shapes to render to your console:
Rectangle
Square
Triangle
Trapezoid
Parallelogram
Circle
Arc
Ellipsis
They implement the GraphicalCyclicWriter and the CyclicWriter classes to allow you to iteratively render different geometric shapes from arrays of shapes that you can loop through to speed up the process and to allow you to implement your custom geometric shape.
You can also store these shapes in a container and render them iteratively using the class. For line rendering, we recommend that you rely on the cyclic writer and its renderables.
To render a geometric shape, such as a rectangle, to the console, you must create a new instance of a shape class, providing the width and the height of the shape, as well as the position that tells Terminaux where to render the shape, whether to render the outline or the full shape (optional), and the selected color (optional).
It's up to your shape class to have a constructor that doesn't necessarily require all the shape arguments as outlined above.
After creating a new instance, just call Render() on the shape instance.
RenderRectangle.cs
var rect = new Rectangle(7, 5, 4, 2, true, ConsoleColors.Red);
var rect2 = new Rectangle(7, 5, 21, 2, false, ConsoleColors.Aqua);
TextWriterRaw.WriteRaw(rect.Render());
TextWriterRaw.WriteRaw(rect2.Render());
You can render the following shapes directly to your console:
Circle
The circle writer allows you to write a circle to the console. It also allows you to either draw just an outline or the whole filled circle.
var shape = new Circle(20, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Circle(20, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Arc
This writer allows you to write an arc directly to the console with some parameters, such as custom inner and outer radius, and angle ranges.
This writer allows you to write an ellipsis directly to the console. It also allows you to either draw just an outline or the whole filled ellipsis.
var shape = new Ellipsis(20, 15, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Ellipsis(20, 15, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Parallelogram
This writer allows you to write a parallelogram to the console directly. You can specify whether to draw just the outline or the whole shape.
var shape = new Parallelogram(20, 10, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Parallelogram(20, 10, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Rectangle
This writer allows you to write a rectangle to the console directly. You can specify whether to print the whole shape or just the edges.
var shape = new Rectangle(20, 10, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Rectangle(20, 10, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Square
This shape basically renders a rectangle, but with just the height specified. In the console, the width is multiplied by two due to the space widths taking up only one cell. It basically renders a square.
var shape = new Square(20, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Square(20, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Trapezoid
This renders a trapezoid using a specified height, a top edge width, and a bottom edge width. You can also make it either render just the outline or as a full shape.
var shape = new Trapezoid(10, 30, 20, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Trapezoid(10, 30, 20, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Triangle
This renders either an equilateral triangle or an isosceles triangle to the console.
var shape = new Triangle(30, 20, 2, 1);
TextWriterRaw.WriteRaw(shape.Render());
var shape = new Triangle(30, 20, 2, 1, true);
TextWriterRaw.WriteRaw(shape.Render());
Line
This renders either a rough line or a smooth line, and it can either be half-width or full-width.
var line = new Line()
{
StartPos = new(2, 2),
EndPos = new(10, 5)
};
TextWriterRaw.WriteRaw(line.Render());
var line = new Line()
{
StartPos = new(2, 2),
EndPos = new(10, 5),
AntiAlias = true,
};
TextWriterRaw.WriteRaw(line.Render());