class Drawille::Canvas
Attributes
chars[R]
Public Class Methods
new()
click to toggle source
# File lib/drawille/canvas.rb, line 8 def initialize clear @snapshots = [{}] end
Public Instance Methods
[]=(x, y, bool)
click to toggle source
# File lib/drawille/canvas.rb, line 37 def []= x, y, bool bool ? set(x, y) : unset(x, y) end
clear()
click to toggle source
# File lib/drawille/canvas.rb, line 18 def clear @chars = Hash.new { |h,v| h[v] = Hash.new(0) } end
convert(x, y)
click to toggle source
# File lib/drawille/canvas.rb, line 48 def convert x, y x = x.round y = y.round [x, y, (x / 2).floor, (y / 4).floor] end
get(x, y)
click to toggle source
# File lib/drawille/canvas.rb, line 32 def get x, y x, y, px, py = convert x, y @chars[py][px] & PIXEL_MAP[y % 4][x % 2] != 0 end
Also aliased as: []
paint(&block)
click to toggle source
# File lib/drawille/canvas.rb, line 13 def paint &block Brush.new(self).instance_eval(&block) self end
set(x, y)
click to toggle source
# File lib/drawille/canvas.rb, line 22 def set x, y x, y, px, py = convert x, y @chars[py][px] |= PIXEL_MAP[y % 4][x % 2] end
toggle(x, y)
click to toggle source
# File lib/drawille/canvas.rb, line 43 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)
click to toggle source
# File lib/drawille/canvas.rb, line 27 def unset x, y x, y, px, py = convert x, y @chars[py][px] &= ~PIXEL_MAP[y % 4][x % 2] end