Sha256: 902c7c118da77b698fddc6a02542f7a62e8e30c8b7ea7699b385bf3a748b9ad0

Contents?: true

Size: 965 Bytes

Versions: 4

Compression:

Stored size: 965 Bytes

Contents

#
# Wolfram Cellular Automata
# by Daniel Shiffman.  
# see one example at http://en.wikipedia.org/wiki/Rule_30
# where current pattern	 111 110	101	100	011	010	001	000
# new state for center cell	0	0	0	1	1	1	1	0
# Simple demonstration of a Wolfram 1-dimensional cellular automata
# When the system reaches bottom of the window, it restarts with a new ruleset
# Mouse click restarts as well. 
#
load_library 'ca'
 
attr_reader :ca   # An instance object to describe the Wolfram basic Cellular Automata

def setup
  size(640, 360, P2D)
  frameRate(30)
  background(0)
  ruleset = [0, 1, 0, 1, 1, 0, 1, 0]    # An initial rule system
  @ca = CA.new(ruleset)          # Initialize CA
end

def draw
  ca.render    # Draw the CA
  ca.generate  # Generate the next level  
  if ca.finished?  # If we're done, clear the screen, pick a new ruleset and restart
    init!
  end
end

def init!
  background(0)
  ca.randomize
  ca.restart
end

def mouse_pressed
  init!
end



Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-2.4.4 samples/processing_app/topics/cellular_automata/wolfram.rb
ruby-processing-2.4.3 samples/processing_app/topics/cellular_automata/wolfram.rb
ruby-processing-2.4.2 samples/processing_app/topics/cellular_automata/wolfram.rb
ruby-processing-2.4.1 samples/processing_app/topics/cellular_automata/wolfram.rb