28 August 2012

An arbitrary L-system

In CSC2003S (game design) today we had a brief look at L-systems.  In particular we examined this L-system for a turtle:
  • ω: xF
  • P_0: x<F → yF+(30)xF
  • P_1: +(a) → +(a-2)
  • P_2: y<F → FF
where F represents drawing a segment and +(a) represents turning a degrees.  Other symbols are ignored by the turtle.

For up to 30 iterations, this makes a pretty cool sort of flattened spiral.  Once you pass that, though, it also circles the other way, and once you reach around 60 iterations things just get weird as the angles eventually become acute, then finally wrap back to 30.

Have a look at some code I wrote to evolve and draw the L-system.  You'll need Python >2.6 installed to run it.

Here's a screenshot with 100 iterations.