Class: LetItFall::Render
- Inherits:
-
Object
- Object
- LetItFall::Render
- Defined in:
- lib/let_it_fall.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mark, screen, color: nil, interval: 0.1, matrix: false, auto: nil) ⇒ Render
constructor
auto: nil or interval time(Integer).
- #run ⇒ Object
Constructor Details
#initialize(mark, screen, color: nil, interval: 0.1, matrix: false, auto: nil) ⇒ Render
auto: nil or interval time(Integer)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/let_it_fall.rb', line 12 def initialize(mark, screen, color:nil, interval:0.1, matrix:false, auto:nil) @y, @x = screen if [nil, *31..37].include?(color) @color = color else raise ArgumentError, "color should be 31-37 or nil" end @mark = mark @interval = interval @screen = {} @matrix = matrix @auto = auto $stdout.sync = true end |
Class Method Details
.run(mark, screen, color: nil, interval: 0.1, matrix: false, auto: nil) ⇒ Object
7 8 9 |
# File 'lib/let_it_fall.rb', line 7 def self.run(mark, screen, color:nil, interval:0.1, matrix:false, auto:nil) new(mark, screen, color:color, interval:interval, matrix:matrix, auto:auto).run end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/let_it_fall.rb', line 27 def run clear_screen marks = build_marks(@mark) Thread.new do while STDIN.getc # hit return marks = select_next_marks(@mark) end end trap(:INT) do exit(0) end t = Time.now loop do if @auto && Time.now - t > @auto marks = select_next_marks(@mark) t = Time.now end print_marks(rand(@x), 0, marks) sleep @interval end ensure reset_screen end |