class Opal::UI::MaskMap

Overview

A 2D normalized weight map (values from 0.0 to 1.0) used for alpha stencil masking, spotlights, and feathered dithering effects in terminal screen buffers.

Defined in:

opal/ui/mask.cr

Constant Summary

DITHER_CHARS = Opal::Glyphs::Shades

Shading characters for dithering fractional alpha values: 0.0 -> 1.0

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.box(bx : Int32, by : Int32, bw : Int32, bh : Int32, feather : Float64 = 0.0, width : Int32 = 80, height : Int32 = 25) : MaskMap #

Generates a rectangular box mask with optional feathering around its perimeter


[View source]
def self.checkerboard(tile_w : Int32 = 4, tile_h : Int32 = 2, width : Int32 = 80, height : Int32 = 25) : MaskMap #

Generates a checkerboard mask pattern


[View source]
def self.linear_gradient(angle_degrees : Float64, width : Int32 = 80, height : Int32 = 25, start_val : Float64 = 0.0, end_val : Float64 = 1.0) : MaskMap #

Generates a linear gradient mask along a specified angle (in degrees, 0 = left-to-right, 90 = top-to-bottom)


[View source]
def self.new(width : Int32, height : Int32, initial_weight : Float64 = 1.0) #

[View source]
def self.radial(cx : Float64 | Int32, cy : Float64 | Int32, radius : Float64, feather : Float64 = 0.0, width : Int32 = 80, height : Int32 = 25, aspect_ratio : Float64 = 2.0) : MaskMap #

Generates a circular or elliptical radial mask centered at (cx, cy) with optional feathering. Terminal cells have an aspect ratio of roughly 2:1 (height:width), which is compensated for.


[View source]
def self.stencil(lines : Array(String), width : Int32 | Nil = nil, height : Int32 | Nil = nil) : MaskMap #

Generates a stencil mask from an array of ASCII strings (non-space characters become 1.0)


[View source]

Class Method Detail

def self.dither_char(weight : Float64) : Char #

Returns a dither shade character for a given alpha weight (0.0..1.0)


[View source]

Instance Method Detail

def [](x : Int32, y : Int32) : Float64 #

[View source]
def []=(x : Int32, y : Int32, weight : Float64) : Nil #

[View source]
def blend(other : MaskMap, mode : Symbol = :multiply) : MaskMap #

Blends this mask with another mask using :multiply, :screen, :add, or :subtract


[View source]
def fill(weight : Float64) : Nil #

[View source]
def get(x : Int32, y : Int32) : Float64 #

[View source]
def height : Int32 #

[View source]
def in_bounds?(x : Int32, y : Int32) : Bool #

[View source]
def invert : MaskMap #

Inverts all mask weights (1.0 - weight)


[View source]
def set(x : Int32, y : Int32, weight : Float64) : Nil #

[View source]
def weights : Array(Float64) #

[View source]
def width : Int32 #

[View source]