Class: UnicodePlot::BlockCanvas

Inherits:
LookupCanvas show all
Defined in:
src/lib/unicode_plot/canvas/block_canvas.rb

Overview

The BlockCanvas is also Unicode-based.
It has half the resolution of the BrailleCanvas.
In contrast to BrailleCanvas, the pixels don’t
have visible spacing between them.
This canvas effectively turns every character
into 4 pixels that can individually be manipulated
using binary operations.

Constant Summary collapse

X_PIXEL_PER_CHAR =
2
Y_PIXEL_PER_CHAR =
2
BLOCK_SIGNS =
[
  [0b1000, 0b0010].freeze,
  [0b0100, 0b0001].freeze
].freeze
BLOCK_DECODE =
[
  -' ', -'', -'', -'',
  -'', -'', -'', -'',
  -'', -'', -'', -'',
  -'', -'', -'', -''
].freeze

Constants inherited from Canvas

Canvas::CANVAS_CLASS_MAP

Constants included from StyledPrinter

StyledPrinter::COLOR_DECODE, StyledPrinter::COLOR_ENCODE, StyledPrinter::DISABLE_TEXT_STYLE, StyledPrinter::TEXT_COLORS

Instance Attribute Summary

Attributes inherited from Canvas

#height, #origin_x, #origin_y, #pixel_height, #pixel_width, #plot_height, #plot_width, #width, #x_pixel_per_char, #y_pixel_per_char

Instance Method Summary collapse

Methods inherited from LookupCanvas

#pixel!, #print_row

Methods inherited from Canvas

#char_at, #color_at, create, #index_at, #line!, #lines!, #point!, #points!, #print, #show

Methods included from BorderPrinter

#print_border_bottom, #print_border_top

Methods included from StyledPrinter

#print_color, #print_styled

Constructor Details

#initialize(width, height, fill_char = 0, **kw) ⇒ BlockCanvas

Returns a new instance of BlockCanvas.



15
16
17
18
19
20
21
# File 'src/lib/unicode_plot/canvas/block_canvas.rb', line 15

def initialize(width, height, fill_char=0, **kw)
  super(width, height,
        X_PIXEL_PER_CHAR,
        Y_PIXEL_PER_CHAR,
        fill_char,
        **kw)
end

Instance Method Details

#lookup_decode(x) ⇒ Object



36
# File 'src/lib/unicode_plot/canvas/block_canvas.rb', line 36

def lookup_decode(x) ; BLOCK_DECODE[x] ; end

#lookup_encode(x, y) ⇒ Object



35
# File 'src/lib/unicode_plot/canvas/block_canvas.rb', line 35

def lookup_encode(x,y) ; BLOCK_SIGNS[x][y] ; end