We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › L-System Classes
Page Index Toggle Pages: 1
L-System Classes (Read 2928 times)
L-System Classes
Jul 9th, 2005, 11:41pm
 
http://www.blprnt.com/processing/simpletrees

I've ported my L-systems Classes from ActionScript to Processing. They support the creation of multi-rule L-systems with stochastic variation. Contextual variation is included in the AS versions, but I haven't built it in here (though it wouldn't be that hard to add).

To demo it, I've built a simple rendering system for building 3D trees and bushes. It's fairly simple right now - leaves only. It's more for the demonstration of how the Classes are implemented.

I am also working on a sound engine, which will generate music from an L-system, but it isn't quite working the way I want it yet.

Feel free to use this any way you want.
Re: L-System Classes
Reply #1 - Sep 22nd, 2005, 10:52pm
 
I've cleaned up the code and posted source for my Processing L-system trees:

http://www.blprnt.com/processing/cherrytree/

http://www.blprnt.com/processing/birchtree/

http://www.blprnt.com/processing/showtree/

All three are quite similar. The birch and the cherry have slightly different leaves and slightly different tree-rendering settings - they also gather their colours from different images. The show tree is my webcam tree, and requires a webcam to be connected.

Some easy fun could be had with these by editing the Leaf class - it'd be cool to see what people come up with.
Re: L-System Classes
Reply #2 - Oct 12th, 2005, 8:10pm
 
I wonder if there's some L-system stuff in Flash. And if there is, why haven't people done stuff with it. Not much visible out there.

Ritwik
Re: L-System Classes
Reply #3 - Oct 12th, 2005, 11:26pm
 
I have L-system classes built for Flash.

http://www.blprnt.com/swf/lsystem.html
http://www.blprnt.com/swf/tree.html

Fire me an e-mail if you want the source.
Re: L-System Classes
Reply #4 - Apr 18th, 2006, 4:45pm
 
I'm building a new project for my end of year show based on the  video-video game I just finished off.

One of the criticisms I got was that it was a lot of fun playing this wierd game, but it wasn't really art - it was after all just a big video game.

So I have an accidental piece of video rope I've made now and it occurs to me that I like how people are transfixed when you give them a task to enjoy your work. So I'm gonna have them use the video rope to knock balls into goals on either side of the screen. That's already figured out and tested.

These balls could be seeds, seeds that grow L-Systems behind. Perhaps those L-Systems could drop more seeds Rather like Ornamental Bug Garden but objective, so the viewer is participating in growing the work. I'll be wanting to add sound to it as well so the trees grow as the viewer plays.

So this is a shout out for L-System stuff. I'm going to hassle Blprnt first obviously, but if anyone has any links tucked away could you please append this thread.
Re: L-System Classes
Reply #5 - Apr 18th, 2006, 5:59pm
 
The Algorithmic Botany site has to be the motherlode of theory on L-Systems.
Re: L-System Classes
Reply #6 - Apr 18th, 2006, 10:37pm
 
I've found an isolated LSystem class in Java and brought it into Processing.

http://www.javaview.de/vgp/tutor/lsystem/PaLSystem.html

I did originally post this as a cry for help, but I've sat down and studied blprnt's code and the applet above and found out that I just needed to scale the drawing down each iteration - that was how the seemingly clever reduction of the branches was achieved.

Posting another ream of code seemed a bit pedantic so I've posted up the Processing "Hello World" LSystem for all instead.
Code:

LSystem lsystem;
int iterations = 1;
float step;
void setup(){
size(400, 400);
lsystem = new LSystem("F", "F[+F]F[-F]F");
lsystem.iterate(iterations);
fitStep();
println(lsystem.tree);
smooth();
}
void draw(){
background(255);
lsystem.draw(0, height / 2, step, HALF_PI);
}
void fitStep(){
int pushed = 0;
int scaling = 0;
for(int i = 0; i < lsystem.tree.length(); i++){
switch(lsystem.tree.charAt(i)){
case 'F':
if(pushed == 0)
scaling++;
break;
case '[':
pushed++; break;
case ']':
pushed--;
break;
}
}
step = (float)width / scaling;
}
void keyPressed(){
lsystem.iterate(++iterations);
fitStep();
}
class LSystem {
char [] alphabet = {
'F', '+', '-', '[', ']'};
String axiom;
String [] rule = {
"", "+", "-", "[", "]"};
String tree;
LSystem(String axiom, String ruleset){
rule[0] = ruleset;
this.axiom = axiom;
tree = "";
}
void draw(float x, float y, float step, float angle){
pushMatrix();
translate(x,y);
for(int i = 0; i < tree.length(); i++){
switch(tree.charAt(i)){
case 'F':
line(0, 0, step, 0);
translate(step, 0);
break;
case '+':
rotate(angle);
break;
case '-':
rotate(-angle);
break;
case '[':
pushMatrix(); break;
case ']':
popMatrix();
break;
}
}
popMatrix();
}
void iterate(int maxLength){
println(tree);
tree = new String(axiom);
int [] ruleLength = new int[alphabet.length];
for (int i = 0; i < alphabet.length; i++){
ruleLength[i] = rule[i].length();
}
for (int i = 0; i < maxLength; i++){
int newLength = 0;
for (int j = 0; j < tree.length(); j++){
char c = tree.charAt(j);
for (int k = 0; k < alphabet.length; k++){
if (c == alphabet[k]){
newLength += ruleLength[k];
break;
}
}
}
StringBuffer newTree = new StringBuffer(newLength);
for (int j = 0; j < tree.length(); j++){
char c = tree.charAt(j);
for (int k = 0; k < alphabet.length; k++){
if (c == alphabet[k]){
newTree.append(rule[k]);
break;
}
}
}
tree = newTree.toString();
}
}
}

Thankyou watz for the link. Any further resources I shall add to this thread.
Re: L-System Classes
Reply #7 - Apr 21st, 2006, 3:53pm
 
For those of you who still don't know what exactly an L-System is yet you might find this link helpful. It's friendly to idiots like me and it cleared up in my mind what all of the funny notation business was about.

Just typing "L-System java" into Google got me a whole host of handy stuff.

A Java applet demonstrating a whole host of classic L-Systems

L-System tutorial with rulesets

Two applets demonstrating theory and method

Applet with a lot of rulesets you can steal

An L-System Explorer (Windows only)
Re: L-System Classes
Reply #8 - Apr 25th, 2006, 6:20am
 
In addition to the links above I found the book, The Algorithmic Beauty of Plants, originally printed by Springer-Verlag to be very helpful as an introduction. And guess what - it's available for free online. (wow)

a host of amazing algorithmic papers:
http://algorithmicbotany.org/papers/#abop

or direct link to the book:
http://algorithmicbotany.org/papers/abop/abop.pdf
Re: L-System Classes
Reply #9 - Jul 9th, 2006, 11:11am
 
In in Prague at the moment for Transistor. Julian Oliver of SelectParks gave us a talk about games and simulation and then lead us through Blender.

Feeling pretty stoked I gave Python a serious look over and tried my first bit of Python code today:
Code:

#unfortunately the tabbing don't quite work here
class LSystem:
def __init__(self, seed):
self.alphabet = ['f', '+', '-', '[', ']']
self.rule = ['f', '+', '-', '[', ']']
self.tree = ''
self.rule[0] = seed
def iterate(self, maxLength):
self.tree = self.rule[0]
for i in range(maxLength):
self.newTree = ''
for j in range(len(self.tree)):
for k in range(len(self.alphabet)):
if self.tree[j] == self.alphabet[k]:
self.newTree += self.rule[k]
self.tree = self.newTree

It took quite a few tries and I think I may have gotten some of it wrong but it is indeed half the code I would normally write and I can use it in Blender.

I passed up the idea of doing 3D L-Systems in Processing but I quite fancy making a 3D LSystem constructor for Blender.

Funny thing is though that I would certainly get the conceptual sketch running in Processing first, unless of course you guys know a sketch environment for Python.
Page Index Toggle Pages: 1