Class: Drawille::FlipBook
- Inherits:
-
Object
- Object
- Drawille::FlipBook
show all
- Includes:
- Frameable
- Defined in:
- lib/drawille/flipbook.rb
Constant Summary
Constants included
from Frameable
Drawille::Frameable::BRAILLE_CHAR_OFFSET, Drawille::Frameable::PIXEL_MAP
Instance Method Summary
collapse
Methods included from Frameable
#char, #frame, #row, #rows, #to_braille
Constructor Details
Returns a new instance of FlipBook.
9
10
11
|
# File 'lib/drawille/flipbook.rb', line 9
def initialize
clear
end
|
Instance Method Details
#clear ⇒ Object
13
14
15
16
|
# File 'lib/drawille/flipbook.rb', line 13
def clear
@snapshots = []
@chars = {}
end
|
#each_frame(options = {}) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/drawille/flipbook.rb', line 23
def each_frame options={}
return enum_for(__callee__) unless block_given?
@snapshots.each do |frame|
yield frame
end
end
|
#play(options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/drawille/flipbook.rb', line 30
def play options={}
options = {
repeat: false, fps: 6,
min_x: 0, min_y: 0
}.merge(options)
Curses::init_screen
begin
Curses::crmode
Curses::curs_set 0
repeat options do
if block_given?
loop {
canvas = yield
raise StopIteration if canvas == nil
draw canvas.frame
}
else
each_frame options do |frame|
draw frame
sleep(1.0/options[:fps])
end
end
end
ensure
Curses::close_screen
end
end
|
#repeat(options) ⇒ Object
59
60
61
|
# File 'lib/drawille/flipbook.rb', line 59
def repeat options
options[:repeat] ? loop { yield; clear_screen options } : yield
end
|
#snapshot(canvas) ⇒ Object
18
19
20
21
|
# File 'lib/drawille/flipbook.rb', line 18
def snapshot canvas
@snapshots << canvas.frame
@chars = canvas.chars
end
|