Algorithmic Form
|
IntroductionThe tutorial, "Algorithmic Form: Basic CA Python Classes", presented two python classes that implement the logic that underpins the classes developed in this tutorial. The two classes presented in listing 1, CellularPlanes.py, enable a cellular automata to be modelled in Maya as a grid of instanced shapes - figure 1.
|
The MayaCell Class
This is a subclass of self.tformNode = mc.instance(MayaCell.shape)[0]
By default, the master shape is a Maya
polyPlane and the attribute that responds to the state of a def __init__(self, chance):
# Call the super class init method
CA.Cell.__init__(self, chance)
self.tformNode = mc.instance(MayaCell.shape)[0]
mc.xform(self.tformNode, piv = MayaCell.pivot)
Setting the pivot is of no importance to a polyPlane but it is important when other
Maya shapes are used. For example, before an instance of the mc.delete(MayaCell.shape) MayaCell.shape = mc.polyCube(w = 0.8, h = 0.8, d = 0.8) MayaCell.attrName = ".scaleY" MayaCell.attrIncr = 1 MayaCell.pivot = (0, -0.4, 0)
The setState() method enables a variety of potentially interesting visual effects to be easily achieved (figures 3 & 4). If the reader wishes the Maya shape that represents a cell to have more than one attribute effected by a cell's state they should create their own subclass of AbstractAutomata.Cell. |
|
|
Running the Automata
Execute code shown below in Maya's script window - ensure the Python
tab is active!
import maya.cmds as mc
import random
import CellularPlanes
# Use reload if CellularPlanes.py is modified
#reload(CellularPlanes)
# To replace the default shape with one of your choosing
# the next 5 lines of code must be un-commented
#mc.delete(MayaCell.shape)
#CellularPlanes.MayaCell.shape = mc.polyCube(w = 0.8, h = 0.8, d = 0.8)
#CellularPlanes.MayaCell.attrName = ".scaleY"
#CellularPlanes.MayaCell.attrIncr = 1
#CellularPlanes.MayaCell.pivot = (0, -0.4, 0)
# Lock the random number generator
random.seed(1)
# Create the automata with 16 cells along
# the X axis and 10 cells along the Z axes
automata = CellularPlanes.MayaAutomata(16, 10, 0.5)
generations = 10
for n in range(generations):
mc.currentTime(n)
automata.nextGeneration()
|
|
Listing 1 (CellularPlanes.py)
|
© 2002- Malcolm Kesson. All rights reserved.