module
Opal::Graphics::Primitives2D
Overview
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.
Defined in:
opal/graphics/primitives_2d.crClass Method Summary
- .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
-
.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
-
.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
-
.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.
-
.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
-
.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.
-
.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
-
.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
-
.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
-
.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
- .ellipse(buffer : UI::Buffer, cx : Int32, cy : Int32, rx : Int32, ry : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none) : Nil
-
.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
-
.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
-
.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
-
.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
-
.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
- .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
- .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
Class Method Detail
Draws a circle using midpoint algorithm with terminal aspect ratio compensation
Draws an ellipse using the midpoint algorithm
Draws a 2D regular character grid inside the specified rectangle.
Fast horizontal line
Draws a line between (x0, y0) and (x1, y1) using integer Bresenham algorithm.
Draws an outlined rectangle using border characters
Draws a shaded drop shadow along the right and bottom sides of a box
Draws a wireframe triangle
Fast vertical line
Fills a circle/ellipse
Fills a rectangle with character and styling
Scanline-fills a triangle
Alias for draw_grid
Convenience aliases for intuitive graphics scripting