giving something back to the Flash community

L-system bis repetita

Tags: , , ,

lsystem cover
I’m currently working on the content of the workshop I’ll give next month to the CRMA students. this gives me the opportunity to dive deep into all I know about geometry, patterns and shapes generation.

one thing I had done quite a while ago is to build a L-system (lire l’article ici) and at the time I didn’t quite understand what was going on.
so I took a second take based on the processing class by Geraldine Sarmiento itself based on a class by by Patrick Dwyer and ended up with a pair of classes that work better and faster. overmore I know exactly what’s happening this time ^^.

as such, the class is very basic ; it only handles the 5 instructions ‘f’, ‘+’, ‘-’, ‘[', and ']‘.
it should be enhanced/extended to perform extra tasks, like using different sets of rules or add some instructions( ‘G’, the ‘jump’ for instance).

here’s a demo:

the top left textfield is tha xiom, under which you have the rule, then the length.
the numeric stepper on top is the delta, the other sets the theta and generations computes X generations.
once drawn, you can drag/drop the system. you should try with 1 or 2 generations before you go for lots of computation.

here’s the Lsystem class and the Turtle class (actually the turtle could be a Vector3D where the angle is stored in the Z property).

that’s how you run it:

//assigns the axiom, rule, length of each segment, theta(start anle), delta (step angle)
var ls:Lsystem = new Lsystem( 'f', 'f+f-f-f+f', 20, Math.PI, Math.PI * .5 );
addChild( ls );
ls.compute( 3 );//computes 3 generations
ls.render();//renders the system

note that the theta/delta should be set in radians the axiom and rules are case insensitive.

the code above should give you this:

here’s a couple of outputs:
and for instance the shape below
is given by the formula hereunder:

a: Ff-FF–FF+FF
r: F – F++[F - ff + fffff - ff - f] + F[ +f - F + ] – F – F
t: 45
d: 37

here’s a couple of formulae that turned out to work nicely:

a: F
r: F+F-F-F+F
t: 180
d: 90

a: f-f-f-f-f
r: FF-[-F+F+F]+[+F-F-F]
t: 180
d: 90

a: F
r: F+F-F-F+F[F++F--]++
t: 0
d: 60

a: f+f+f
r: F+Ff+f+ff-f-ff
t: 0
d: 120

more on Flickr
I guess that was it.

Tags: , , ,

© 2009 HIDIHO!. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.