Experiment: Electronic Life
24 Jan 2015
Here is a short sample of some code from the exercise.
There is quite a bit missing from this snippet but hopefully you can get a feel for the style of the code.
When an object is needed it is invoked with the new keyword, as in
new Vector(0, -1).
The BouncingCritter class is defined and given one property:
direction. To add behaviour a function is attached to the prototype.
For a much better explanation of why things are done this way check out the exercise in full.
The silly bouncing critters simply look for a random empty space nearby using
view.find(). If they can’t find one they head south. They aren’t terribly smart.
On a related topic…
This exercise sparked my interest in exploring natural simulations in the browser. It turns out I’m not the only one interested in this. I found an incredibly fun looking library that provides tools for doing this easily. It’s called FloraJS. If Electronic Life seems fun, just wait until you see what FloraJS can do!