class

Opal::UI::EquationViewer

Inherits Opal::UI::Control < Opal::UI::InputHookable < Opal::UI::Element < Opal::UI::Themable < Reference < Object

Mathematical equation viewer and interactive 2D function grapher. Features 2D Unicode mathematical typesetting (fractions, integrals, radicals, summations) and interactive Cartesian graphing f(x) with braille sub-pixel rendering, zoom, and pan.

Constants

SUBSCRIPTS = {'0' => '₀', '1' => '₁', '2' => '₂', '3' => '₃', '4' => '₄', '5' => '₅', '6' => '₆', '7' => '₇', '8' => '₈', '9' => '₉', '+' => '₊', '-' => '₋', '=' => '₌', '(' => '₍', ')' => '₎', 'a' => 'ₐ', 'e' => 'ₑ', 'i' => 'ᵢ', 'j' => 'ⱼ', 'k' => 'ₖ', 'n' => 'ₙ', 'x' => 'ₓ'}
SUPERSCRIPTS = {'0' => '⁰', '1' => '¹', '2' => '²', '3' => '³', '4' => '⁴', '5' => '⁵', '6' => '⁶', '7' => '⁷', '8' => '⁸', '9' => '⁹', '+' => '⁺', '-' => '⁻', '=' => '⁼', '(' => '⁽', ')' => '⁾', 'n' => 'ⁿ', 'i' => 'ⁱ', 'x' => 'ˣ', 'y' => 'ʸ'}

Unicode character map for superscripts and subscripts

Constructors

new(function_title : String = "f(x) = sin(x)", x_min : Float64 = -5.0, x_max : Float64 = 5.0, y_min : Float64 = -3.0, y_max : Float64 = 3.0, width : Int32 = 42, height : Int32 = 16, function : Proc(Float64, Float64) | Nil = nil)
Source
new(function_title : String = "f(x) = sin(x)", x_min : Float64 = -5.0, x_max : Float64 = 5.0, y_min : Float64 = -3.0, y_max : Float64 = 3.0, width : Int32 = 42, height : Int32 = 16, &block : Float64 -> Float64)
Source

Class methods

format_super_sub(expr : String) : String

Converts a regular string with ^(exp) or _(sub) into Unicode super/subscripts

Source
sqrt_text(inner : String) : String

Formats a square root: √(expr) with Unicode overbar

Source

Instance methods

add_fraction(num : String, den : String) : Nil

Adds a fraction node

Source
add_integral(lower : String, upper : String, integrand : String) : Nil

Adds an integral node

Source
add_text(text : String) : Nil

Adds a text node

Source
axis_color
Source
axis_color=(axis_color : Color)
Source
border_color
Source
border_color=(border_color : Color)
Source
curve_color

Colors

Source
curve_color=(curve_color : Color)

Colors

Source
formula_color
Source
formula_color=(formula_color : Color)
Source
function

Function to graph: receives float x and returns float y = f(x)

Source
function=(function : Proc(Float64, Float64) | Nil)

Function to graph: receives float x and returns float y = f(x)

Source
function_title
Source
function_title=(function_title : String)
Source
grid_color
Source
grid_color=(grid_color : Color)
Source
handle_key(key : Terminal::KeyEvent) : Bool

Default key event handler. Override in subclasses if not using @default_input_proc.

Source
handle_mouse(event : Terminal::MouseEvent) : Bool

Default mouse event handler. Override in subclasses if not using @default_input_proc.

Source
height
Source
height=(height : Int32)
Source
last_h
Source
last_h=(last_h : Int32)
Source
last_w
Source
last_w=(last_w : Int32)
Source
last_x
Source
last_x=(last_x : Int32)
Source
last_y
Source
last_y=(last_y : Int32)
Source
math_nodes
Source
math_nodes=(math_nodes : Array(MathNode))
Source
pan(dx_pct : Float64, dy_pct : Float64) : Nil

Pans viewport

Source
preferred_size(available_w : Int32, available_h : Int32) : Tuple(Int32, Int32)
Source
render(buffer : Buffer, x : Int32, y : Int32, width : Int32, height : Int32) : Nil
Source
render(buffer : Buffer) : Nil
Source
show_formula=(show_formula : Bool)
Source
show_formula?
Source
show_graph=(show_graph : Bool)

Display settings

Source
show_graph?

Display settings

Source
width
Source
width=(width : Int32)
Source
x_max
Source
x_max=(x_max : Float64)
Source
x_min

Viewport bounds

Source
x_min=(x_min : Float64)

Viewport bounds

Source
y_max
Source
y_max=(y_max : Float64)
Source
y_min
Source
y_min=(y_min : Float64)
Source
zoom(factor : Float64) : Nil

Zooms in/out

Source

Nested types