module

Opal::Graphics::Primitives2D

2D geometry rasterization primitives for terminal buffers. Provides Bresenham line drawing, rectangles, midpoint circles/ellipses with aspect ratio compensation, drop shadows, and scanline-filled triangles.

Class methods

circle(buffer : UI::Buffer, cx : Int32, cy : Int32, radius : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none, aspect_ratio : Float64 = 2.0) : Nil
Source
draw_circle(buffer : UI::Buffer, cx : Int32, cy : Int32, radius : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none, aspect_ratio : Float64 = 2.0) : Nil

Draws a circle using midpoint algorithm with terminal aspect ratio compensation

Source
draw_ellipse(buffer : UI::Buffer, cx : Int32, cy : Int32, rx : Int32, ry : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none) : Nil

Draws an ellipse using the midpoint algorithm

Source
draw_grid(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, interval_x : Int32 = 8, interval_y : Int32 = 4, offset_x : Int32 = 0, offset_y : Int32 = 0, style : Symbol | GridStylePreset | GridGlyphs = :solid, fg : Color = Color.none, bg : Color = Color.none, intersection_fg : Color | Nil = nil, major_interval_x : Int32 | Nil = nil, major_interval_y : Int32 | Nil = nil, major_fg : Color | Nil = nil, show_horizontal : Bool = true, show_vertical : Bool = true) : Nil

Draws a 2D regular character grid inside the specified rectangle.

Source
draw_hline(buffer : UI::Buffer, x : Int32, y : Int32, length : Int32, char : Char = '─', fg : Color = Color.none, bg : Color = Color.none, style : Symbol = :solid) : Nil

Fast horizontal line

Source
draw_line(buffer : UI::Buffer, x0 : Int32, y0 : Int32, x1 : Int32, y1 : Int32, char : Char = '─', fg : Color = Color.none, bg : Color = Color.none, style : Symbol = :solid) : Nil

Draws a line between (x0, y0) and (x1, y1) using integer Bresenham algorithm.

Source
draw_rect(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, border : Symbol | Border = :rounded, fg : Color = Color.none, bg : Color = Color.none) : Nil

Draws an outlined rectangle using border characters

Source
draw_shadow(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, shadow_char : Char = '░', fg : Color = Color.rgb(40, 40, 40)) : Nil

Draws a shaded drop shadow along the right and bottom sides of a box

Source
draw_triangle(buffer : UI::Buffer, x0 : Int32, y0 : Int32, x1 : Int32, y1 : Int32, x2 : Int32, y2 : Int32, char : Char = '*', fg : Color = Color.none, bg : Color = Color.none) : Nil

Draws a wireframe triangle

Source
draw_vline(buffer : UI::Buffer, x : Int32, y : Int32, length : Int32, char : Char = '│', fg : Color = Color.none, bg : Color = Color.none, style : Symbol = :solid) : Nil

Fast vertical line

Source
ellipse(buffer : UI::Buffer, cx : Int32, cy : Int32, rx : Int32, ry : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none) : Nil
Source
fill_circle(buffer : UI::Buffer, cx : Int32, cy : Int32, radius : Int32, char : Char = '█', fg : Color = Color.none, bg : Color = Color.none, aspect_ratio : Float64 = 2.0) : Nil

Fills a circle/ellipse

Source
fill_rect(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, char : Char = ' ', fg : Color = Color.none, bg : Color = Color.none) : Nil

Fills a rectangle with character and styling

Source
fill_triangle(buffer : UI::Buffer, x0 : Int32, y0 : Int32, x1 : Int32, y1 : Int32, x2 : Int32, y2 : Int32, char : Char = '█', fg : Color = Color.none, bg : Color = Color.none) : Nil

Scanline-fills a triangle

Source
grid(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, interval_x : Int32 = 8, interval_y : Int32 = 4, offset_x : Int32 = 0, offset_y : Int32 = 0, style : Symbol | GridStylePreset | GridGlyphs = :solid, fg : Color = Color.none, bg : Color = Color.none, intersection_fg : Color | Nil = nil, major_interval_x : Int32 | Nil = nil, major_interval_y : Int32 | Nil = nil, major_fg : Color | Nil = nil, show_horizontal : Bool = true, show_vertical : Bool = true) : Nil

Alias for draw_grid

Source
line(buffer : UI::Buffer, x0 : Int32, y0 : Int32, x1 : Int32, y1 : Int32, char : Char = '─', fg : Color = Color.none, bg : Color = Color.none, style : Symbol = :solid) : Nil

Convenience aliases for intuitive graphics scripting

Source
rect(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, border : Symbol | Border = :rounded, fg : Color = Color.none, bg : Color = Color.none) : Nil
Source
rect_with_shadow(buffer : UI::Buffer, x : Int32, y : Int32, width : Int32, height : Int32, border : Symbol | Border = :rounded, border_fg : Color = Color.none, shadow_char : Char = '░', title : String | Nil = nil) : Nil
Source