Class: Drawille::Canvas
Constant Summary
Constants included
from Frameable
Frameable::BRAILLE_CHAR_OFFSET, Frameable::PIXEL_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Frameable
#char, #frame, #row, #rows, #to_braille
Constructor Details
#initialize ⇒ Canvas
Returns a new instance of Canvas.
9
10
11
12
|
# File 'lib/drawille/canvas.rb', line 9
def initialize
clear
@snapshots = [{}]
end
|
Instance Attribute Details
#chars ⇒ Object
Returns the value of attribute chars.
7
8
9
|
# File 'lib/drawille/canvas.rb', line 7
def chars
@chars
end
|
Instance Method Details
#[]=(x, y, bool) ⇒ Object
38
39
40
|
# File 'lib/drawille/canvas.rb', line 38
def []= x, y, bool
bool ? set(x, y) : unset(x, y)
end
|
#clear ⇒ Object
19
20
21
|
# File 'lib/drawille/canvas.rb', line 19
def clear
@chars = Hash.new { |h,v| h[v] = Hash.new(0) }
end
|
#convert(x, y) ⇒ Object
49
50
51
52
53
|
# File 'lib/drawille/canvas.rb', line 49
def convert x, y
x = x.round
y = y.round
[x, y, (x / 2).floor, (y / 4).floor]
end
|
#get(x, y) ⇒ Object
Also known as:
[]
33
34
35
36
|
# File 'lib/drawille/canvas.rb', line 33
def get x, y
x, y, px, py = convert x, y
@chars[py][px] & PIXEL_MAP[y % 4][x % 2] != 0
end
|
#paint(&block) ⇒ Object
14
15
16
17
|
# File 'lib/drawille/canvas.rb', line 14
def paint &block
Brush.new(self).instance_eval(&block)
self
end
|
#set(x, y) ⇒ Object
23
24
25
26
|
# File 'lib/drawille/canvas.rb', line 23
def set x, y
x, y, px, py = convert x, y
@chars[py][px] |= PIXEL_MAP[y % 4][x % 2]
end
|
#toggle(x, y) ⇒ Object
44
45
46
47
|
# File 'lib/drawille/canvas.rb', line 44
def toggle x, y
x, y, px, py = convert x, y
@chars[py][px] & PIXEL_MAP[y % 4][x % 2] == 0 ? set(x, y) : unset(x, y)
end
|
#unset(x, y) ⇒ Object
28
29
30
31
|
# File 'lib/drawille/canvas.rb', line 28
def unset x, y
x, y, px, py = convert x, y
@chars[py][px] &= ~PIXEL_MAP[y % 4][x % 2]
end
|