class CellWindow
Attributes
board[R]
cell_width[R]
paused[R]
paused?[R]
scale[R]
Public Class Methods
new(opts={})
click to toggle source
Calls superclass method
# 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
Public Instance Methods
draw()
click to toggle source
# 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()
click to toggle source
# File lib/cellular_automata/gui_window.rb, line 40 def toggle_pause @paused = !@paused end
update()
click to toggle source
# File lib/cellular_automata/gui_window.rb, line 12 def update board.tick! unless paused? end