ModernLife A Cellular Automaton implementation
Inherits from: Object
ModernLife is a cellular automaton implementation for SC that also includes some novel alterations to the process. However it can always be used as a standard cellular automaton system. This help file will discuss the standard usage for now.
Creation / Class Methods
*new (argNumDivs, argWinSize)
argNumDivs - Number of cells per row. (default: 50)
argWinSize - Width of the window in pixels. (default: 500)
// the default rule is "23/3" (Conway's Game of Life)
a = ModernLife.new; //will pop up the window
//press space to run/stop. c to clear, r to randomize.
//you can also create or kill cells with mouse interaction.
*loadState (argFile)
Loads the state of the class saved with saveState (see below).
argFile - Path to saved file.
Accessing Instance and Class Variables
fadeAmount_(arg1)
fadeAmount
Opacity of the redraw. Should be between 0 and 1. Lower values leave more traces behind.
currentFps
If the animation is running, it shows the last achieved fps. See the fps variable below. You can use this to see if you are overloading your system or not.
userFunc_(arg1)
userFunc
This is the function you need to provide if you are going to use this system other than visualization purposes. At each generation, this function is passed in the alive/dead state of cells and the population count. The first argument is the states array, which is an array of arrays, where each array is the states of rows from top to bottom. Run the code below:
a = ModernLife.new(8, 80);
a.userFunc_({|states, population| states.postcs; population.postln; });
//press space
The animation runs on SystemClock and the GUI draw operations are deferred but the function is called from outside the deferred block, so timing is accurate for sonification purposes.
fps_(arg1)
fps
You can set the speed of animation (and generation) with this. Default is 10fps (10 generations per second).
Doing Some Task (optional)
setRule (argRuleString)
Sets the rule for the CA system. The notation for the rule is the same used in Mirek's Cellebration. It is a string in the format x/y where x and y are sequence of unique digits between 0 and 8 (inclusive). The digits in x side (for example digit d) means that a live cell with d live neighbors will survive to the next generation (others will die), and a digits in y side (digit k as an example) means that any dead cell with k alive neighbors will come to life. With this scheme, the Conway's Game of Life is defined as "23/3" (which is the default rule.
// conway's gol by default
a = ModernLife.new.play;
a.stop;
//maze
a = ModernLife.new.setRule("12345/3").fps_(5).fadeAmount_(1).play;
a.stop;
//coral
a = ModernLife.new.setRule("45678/3").fps_(25).fadeAmount_(1).play;
a.stop;
//replicator, every pattern is replicated by a copy of itself.
//clear the scene with c and draw a pattern, press space, watch in awe.
a = ModernLife.new.setRule("1357/1357").fps_(10).fadeAmount_(1);
a.stop;
saveScene (argFile)
Saves the scene info to a file. argFile is a path (string).
loadScene (argFile)
Loads the scene info saved with saveScene.
saveState (argFile)
Saves the whole state of the instance (parameters like fps, fade amount and others) into a file to be loaded by ModernLife.loadState.
hideGui
Hides the GUI.
showGui
Shows the GUI.