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.cr

Class Method Summary

Class Method Detail

def self.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 #

[View source]
def self.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


[View source]
def self.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


[View source]
def self.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.


[View source]
def self.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


[View source]
def self.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.


[View source]
def self.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


[View source]
def self.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


[View source]
def self.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


[View source]
def self.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


[View source]
def self.ellipse(buffer : UI::Buffer, cx : Int32, cy : Int32, rx : Int32, ry : Int32, char : Char = '●', fg : Color = Color.none, bg : Color = Color.none) : Nil #

[View source]
def self.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


[View source]
def self.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


[View source]
def self.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


[View source]
def self.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


[View source]
def self.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


[View source]
def self.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 #

[View source]
def self.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 #

[View source]