I was reading Ben Fry's thesis Organic Information Design yesterday, came across the section on Conway's Game of Life, and thought it would make a nice NodeBox demo.
Here it is: conway-life.py
There's not much to it, but it does show a software pattern I've been using frequently with NodeBox. Many of the NodeBox examples make heavy use of non-namespaced global variables. I suppose it makes simple code easy to read for those new to programming, but it's a habit you'll want to break before your code starts getting more complex.
What I've found helpful is to create a World/Universe/Controller/Stage object that drives the rendering. Instead of using multiple globals in draw()
, the controller object keeps the main parameters as local properties, and instantiates any needed objects in it's __init__()
. This approach prevents global variables names from clashing and allows for creative reuse of rendering components.
Enjoy!