forked from red-data-tools/unicode_plot.rb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_canvas.rb
executable file
·38 lines (32 loc) · 1.03 KB
/
block_canvas.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding: utf-8
=begin
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.
=end
module UnicodePlot
class BlockCanvas < LookupCanvas
X_PIXEL_PER_CHAR = 2
Y_PIXEL_PER_CHAR = 2
def initialize(width, height, fill_char=0, **kw)
super(width, height,
X_PIXEL_PER_CHAR,
Y_PIXEL_PER_CHAR,
fill_char,
**kw)
end
BLOCK_SIGNS = [ [0b1000, 0b0010].freeze,
[0b0100, 0b0001].freeze
].freeze
BLOCK_DECODE = [' ', '▗', '▖', '▄',
'▝', '▐', '▞', '▟',
'▘', '▚', '▌', '▙',
'▀', '▜', '▛', '█' ].freeze
def lookup_encode(x,y) ; BLOCK_SIGNS[x][y] ; end
def lookup_decode(x) ; BLOCK_DECODE[x] ; end
end
end