Class: CellWindow
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- CellWindow
- Defined in:
- lib/cellular_automata/gui_window.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#cell_width ⇒ Object
readonly
Returns the value of attribute cell_width.
-
#paused ⇒ Object
(also: #paused?)
readonly
Returns the value of attribute paused.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
-
#initialize(opts = {}) ⇒ CellWindow
constructor
A new instance of CellWindow.
- #toggle_pause ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CellWindow
Returns a new instance of CellWindow.
4 5 6 7 8 9 10 |
# File 'lib/cellular_automata/gui_window.rb', line 4 def initialize(opts={}) @scale = opts[:scale] @cell_width = scale**opts[:cell_scale] super opts[:width]*scale, opts[:height]*scale, opts[:fullscreen] @board = CellularAutomata::Board.new(width: opts[:width]/scale, height: opts[:height]/scale, rule: opts[:rule]) self.caption = "Cellular Automata" end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
2 3 4 |
# File 'lib/cellular_automata/gui_window.rb', line 2 def board @board end |
#cell_width ⇒ Object (readonly)
Returns the value of attribute cell_width.
2 3 4 |
# File 'lib/cellular_automata/gui_window.rb', line 2 def cell_width @cell_width end |
#paused ⇒ Object (readonly) Also known as: paused?
Returns the value of attribute paused.
2 3 4 |
# File 'lib/cellular_automata/gui_window.rb', line 2 def paused @paused end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
2 3 4 |
# File 'lib/cellular_automata/gui_window.rb', line 2 def scale @scale end |
Instance Method Details
#button_down(id) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cellular_automata/gui_window.rb', line 32 def (id) if id == Gosu::KbSpace toggle_pause else exit end end |
#draw ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cellular_automata/gui_window.rb', line 16 def draw board.each_cell do |x, y| prev_1 = board.history[0][y][x] == 1 prev_2 = board.history[1][y][x] == 1 color = Gosu::Color::BLACK if board.state[y][x] == 1 color = Gosu::Color.argb(0xff_FFFF00) elsif prev_1 color = Gosu::Color.argb(0xff_AAAA00) elsif prev_2 color = Gosu::Color.argb(0xff_444400) end Gosu.draw_rect(x * scale**2, y * scale**2, cell_width, cell_width, color, 0, :default) end end |
#toggle_pause ⇒ Object
40 41 42 |
# File 'lib/cellular_automata/gui_window.rb', line 40 def toggle_pause @paused = !@paused end |
#update ⇒ Object
12 13 14 |
# File 'lib/cellular_automata/gui_window.rb', line 12 def update board.tick! unless paused? end |