7. Growth


The study plant and animal growth in the history of science: Linnaeus, Cuvier, Darwin, D’Arcy Wentworth Thompson. Modeling growth with L-systems in Processing (L-systems are also known as string-rewriting systems, various libraries are available and they are actually easy to build from scratch).
Reading: Selections from D’Arcy Wentworth Thompson, On Growth and Form, (BW PDF edition is best) and from Prusinkiewicz and Lindenmayer, The Algorithmic Beauty of Plants (this is the primary source for L-systems, named after Lindenmayer, the entire book is available online).
In On Growth and Form, ch 14 On Leaf-Arrangement, or Phyllotaxis pp 912 to 933. ch xvii On the Theory of Transformations, or the Comparison of Related Forms (starting on p 1026), pp 1038 to 1090.
In The Algorithmic Beauty of Plants, chapter 1, p 13 to 51.

Assignment
Use an L-system to produce graphics or text.

Downloads
TurtleBoids, steering behaviors with a composite boid + turtle.

Programming Patterns
A boid that draws or a turtle that flies? How do we combine two classes? We could: 1. Create a new class, copying code from both sources; 2. Subclass Boid and copy code from Turtle; 3. Subclass Turtle and copy code from Boid; 4. Subclass Boid and include a reference to a Turtle instance; 5. Subclass Turtle and include reference to a Boid instance. Strategies 4 and 5 are known as compositing classes, and are the preferred way to solve our problem. Since we probably want a boid that draws rather than a turtle that flies, let's try strategy 4. We just need to add a Turtle field to a subclass of Boid that we'll call TurtleBoid, along with "accessor" methods to get it and perhaps set it.

If we want to access the Turtle instance's methods without always getting the Turtle instance from TurtleBoid, we can use a "design pattern" called Delegation. Delegation just breaks out some of the Turtle's method signatures and places them in the TurtleBoid class, where they call the identical Turtle methods.

Java interfaces, which are just a way of defining methods and method signatures that we expect to fulfill certain tasks, can further simplify the way we work with classes. A method can accept an interface in its signature, just as it can accept a class. Thus, if we have many different classes that all display the same behavior (in some part of their code), we can declare them as all implementing a perticular interface. We can then pass any of those classes to a method that accepts objects implementing that interface. This is known as "programming to the interface" and is a widely accepted technique for reducing the complexity of code: instead of a method for each class, we opnly need one method for the interface they all use. In the TurtleBoid class, we use a ColorableINF and a BoidCallbackINF.