class Doomfire::Terminal
This class outputs the pixels into the terminal, using ANSI color codes
Public Instance Methods
run()
click to toggle source
# File lib/doomfire/terminal.rb, line 8 def run fire_loop end
stop()
click to toggle source
# File lib/doomfire/terminal.rb, line 12 def stop @exit_requested = true end
Private Instance Methods
clear()
click to toggle source
# File lib/doomfire/terminal.rb, line 43 def clear sleep 0.05 puts "\e[34f\e[f" end
clear_screen()
click to toggle source
# File lib/doomfire/terminal.rb, line 57 def clear_screen puts "\e[2J" puts "\e[H" end
fire_loop()
click to toggle source
# File lib/doomfire/terminal.rb, line 18 def fire_loop loop do if @exit_requested stop_fire if @counter.zero? break if @counter == @fire_height @counter += 1 end update_pixels clear print_pixels end clear_screen end
prepare_output()
click to toggle source
# File lib/doomfire/terminal.rb, line 35 def prepare_output @fire_height = 35 @fire_width = Doomfire::WindowSize.new.terminal_width Paint.mode = 0xFFFFFF Kernel.trap('INT') { @exit_requested = true } clear_screen end
print_pixels()
click to toggle source
# File lib/doomfire/terminal.rb, line 48 def print_pixels (0...@fire_height).each do |x| (0...@fire_width).each do |y| print Paint[' ', nil, RGB[@pixels[x * @fire_width + y]]] end puts end end