class Doomfire::Base
Base
class for the fire algorithm
Constants
- RGB
Attributes
exit_requested[R]
fire_width[R]
pixels[R]
Public Class Methods
new()
click to toggle source
# File lib/doomfire/base.rb, line 46 def initialize @counter = 0 @thread = nil @exit_requested = false prepare_output initialize_pixels end
Public Instance Methods
run()
click to toggle source
# File lib/doomfire/base.rb, line 56 def run raise NotImplementedError end
stop()
click to toggle source
# File lib/doomfire/base.rb, line 60 def stop raise NotImplementedError end
Private Instance Methods
clear()
click to toggle source
# File lib/doomfire/base.rb, line 105 def clear raise NotImplementedError end
clear_screen()
click to toggle source
# File lib/doomfire/base.rb, line 109 def clear_screen raise NotImplementedError end
fire_loop()
click to toggle source
# File lib/doomfire/base.rb, line 101 def fire_loop raise NotImplementedError end
initialize_pixels()
click to toggle source
# File lib/doomfire/base.rb, line 89 def initialize_pixels @pixels = [] last_line = @fire_width * (@fire_height - 1) @pixels.fill(0, 0...last_line) @pixels.fill(34, last_line..(last_line + @fire_width)) end
prepare_output()
click to toggle source
# File lib/doomfire/base.rb, line 96 def prepare_output @fire_width = 80 @fire_height = 35 end
print_pixels()
click to toggle source
# File lib/doomfire/base.rb, line 113 def print_pixels raise NotImplementedError end
spread_fire(src)
click to toggle source
# File lib/doomfire/base.rb, line 66 def spread_fire(src) if @pixels[src].zero? @pixels[src - @fire_width] = 1 else random = rand(10).round & 3 dst = src - rand(3) + 1 @pixels[dst - @fire_width] = @pixels[src] - (random & 1) end end
stop_fire()
click to toggle source
# File lib/doomfire/base.rb, line 76 def stop_fire @pixels.pop(@fire_width) @pixels.concat [].fill(0, 0, @fire_width) end
update_pixels()
click to toggle source
# File lib/doomfire/base.rb, line 81 def update_pixels (1...@fire_height).to_a.reverse.each do |x| (0...@fire_width).each do |y| spread_fire(x * @fire_width + y) end end end