Class: Esolang::Interpreters::Paintfuck
- Inherits:
-
BaseInterpreter
- Object
- BaseInterpreter
- Esolang::Interpreters::Paintfuck
- Defined in:
- lib/interpreters/paintfuck_interpreter.rb
Overview
The Paintfuck class represents an interpreter for the Paintfuck esoteric programming language.
Instance Method Summary collapse
-
#initialize(code, iterations, width, height) ⇒ Paintfuck
constructor
Initializes a new instance of the Paintfuck interpreter.
-
#run ⇒ String
Executes the interpretation of the Paintfuck code.
Constructor Details
#initialize(code, iterations, width, height) ⇒ Paintfuck
Initializes a new instance of the Paintfuck interpreter.
15 16 17 18 19 20 21 22 |
# File 'lib/interpreters/paintfuck_interpreter.rb', line 15 def initialize(code, iterations, width, height) super(code.gsub(/[^nesw\*\[\]]/, '')) @iterations = iterations @width = width @height = height @data_grid = generate_zero_grid @grid_pointer = [0, 0] end |
Instance Method Details
#run ⇒ String
Executes the interpretation of the Paintfuck code.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/interpreters/paintfuck_interpreter.rb', line 27 def run while running? do case command when 'n' then move_up when 'e' then move_right when 's' then move_down when 'w' then move_left when '*' then flip when '[' then loop_begin when ']' then loop_end end @code_pointer += 1 @iterations -= 1 end output end |