Aptivi - Manual
ProjectsWebsiteBlog
Terminaux - Manual
Terminaux - Manual
  • Welcome!
  • Breaking changes
    • API v1.0
    • API v2.0
    • API v3.0
    • API v4.0
    • API v5.0
    • API v6.0
    • API v7.0
  • Usage
    • Preface
    • Console Tools
      • Console Checker
        • Console Size Requirements
      • Image Rendering
        • Icons
      • Console Writers
        • Individual Writers
        • Cyclic Writers
          • Geometric Shapes
          • Charts
          • Text
          • Artistic
          • Progress Bars
          • Lists and Calendars
          • Miscellaneous
        • Informational Boxes
      • Textual UI
        • Interactive TUI
        • Console Screen
        • Console Resize Listener
        • VT Sequences
      • Console Wrapper
      • Console Colors
      • Color Templates
      • Presentation System
      • Console Extensions
      • Nerd Fonts
      • Terminal Info
      • Test Fixtures
      • Terminal Structures
      • Console Logging
    • Input Reader
      • Shells
        • Shell Structure
          • Help System
          • Command Parsing
          • Command Information
          • Command Switches
          • Shell Presets
          • Command Aliasing
      • Other Input
        • Keybindings
        • Choice-based inputs
        • Editors and Viewers
        • Figlet Font Selector
        • Color Wheel
        • Spinner Selector
        • Input Modules
      • Reader State
      • Reader Settings
      • Syntax Highlighting
      • Pointer Events
    • Color Sequences
      • Color Model Conversions
      • Color Model Parsing
      • Interop with System.Drawing.Color
    • Interop with Spectre.Console
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Circle
  • Arc
  • Ellipsis
  • Parallelogram
  • Rectangle
  • Square
  • Trapezoid
  • Triangle
  • Line
Edit on GitHub
  1. Usage
  2. Console Tools
  3. Console Writers
  4. Cyclic Writers

Geometric Shapes

Drawing geometric shapes to the console!

Last updated 9 days ago

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.

var arc = new Arc(20, 4, 2, ConsoleColors.Red)
{
    InnerRadius = 6,
    OuterRadius = 9,
    AngleStart = 360,
    AngleEnd = 100,
};
TextWriterRaw.WriteRaw(arc.Render());
var arc = new Arc(20, 4, 2, ConsoleColors.Red)
{
    InnerRadius = 6,
    OuterRadius = 9,
    AngleStart = 360,
    AngleEnd = 100,
};
var arc2 = new Arc(20, 4, 2, ConsoleColors.Lime)
{
    InnerRadius = 6,
    OuterRadius = 9,
    AngleStart = 150,
    AngleEnd = 300,
};
var arc3 = new Arc(20, 4, 2, ConsoleColors.Blue)
{
    InnerRadius = 6,
    OuterRadius = 9,
    AngleStart = 100,
    AngleEnd = 150,
};
TextWriterRaw.WriteRaw(arc.Render());
TextWriterRaw.WriteRaw(arc2.Render());
TextWriterRaw.WriteRaw(arc3.Render());
var arc = new Arc(20, 4, 2, ConsoleColors.Red)
{
    InnerRadius = 0,
    OuterRadius = 9,
    AngleStart = 170,
    AngleEnd = 120,
};
TextWriterRaw.WriteRaw(arc.Render());
var arc = new Arc(20, 4, 2, ConsoleColors.Red)
{
    InnerRadius = 0,
    OuterRadius = 9,
    AngleStart = 170,
    AngleEnd = 120,
};
var arc2 = new Arc(20, 4, 2, ConsoleColors.Aqua)
{
    InnerRadius = 0,
    OuterRadius = 9,
    AngleStart = 120,
    AngleEnd = 170,
};
TextWriterRaw.WriteRaw(arc.Render());
TextWriterRaw.WriteRaw(arc2.Render());

Ellipsis

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());
Container