Class: Rnes::TerminalRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rnes/terminal_renderer.rb

Constant Summary collapse

BRAILLE_BASE_CODE_POINT =
0x2800
BRAILLE_HEIGHT =
4
BRAILLE_WIDTH =
2
BRIGHTNESS_SUM_THRESHOLD =
256
TEXT_HEIGHT =
61
TEXT_WIDTH =
128
ESCAPE_TO_CLEAR_TEXT =
"\e[#{TEXT_HEIGHT}A\e[#{TEXT_WIDTH}D".freeze

Instance Method Summary collapse

Constructor Details

#initializeTerminalRenderer

Returns a new instance of TerminalRenderer.



17
18
19
20
# File 'lib/rnes/terminal_renderer.rb', line 17

def initialize
  @fps = 0
  @previous_fps = 0
end

Instance Method Details

#render(image) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rnes/terminal_renderer.rb', line 22

def render(image)
  brailles = convert_image_to_string(image)
  fps_counter = "FPS:#{@previous_fps}"
  puts "#{ESCAPE_TO_CLEAR_TEXT}#{fps_counter}\n#{brailles}"
  second = ::Time.now.sec
  if @second == second
    @fps += 1
  else
    @previous_fps = @fps
    @fps = 0
    @second = second
  end
end