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.
IndexProgramming Questions & HelpPrograms › parametric L-system
Page Index Toggle Pages: 1
parametric L-system (Read 1507 times)
parametric L-system
Mar 13th, 2010, 11:08am
 
Hey guys. I've seen a few implementations of L-systems on Processing around, but trying to make a parametric version is being a bit of a pain.

A simple L system is composed of an initial string (an "axiom"), production rules and a resulting string which comes from applying the rules to the current string a bunch of times.

A ruke (on the simple case) just substitutes a character in the current string for a string of characters. Usually these characters are interpreted later as a turtle-graphic code.

So, for example, an L-system with the symbols 'F', '+' and '-', where F makes the turtle move forward (and draw), + and - turn it around. Axiom might be just "F", and the only rule could be "F->F+F". That's a simple case, and in a couple iterations, you would have "F", then "F+F", "F++F+", and so on.

That's a simple case, but you get the idea. It's pretty straightforward to implement on Processing, too.

Now, for parametric L-systems, each character can have some parameters. So, the axiom could be "F(10)", and the rules have conditions on parameters, so for example "F(t):(t>0)->F(t-1)+" and "F(t):(t<=0)->F(10)-" are valid rules.

How would I go about creating those rules I've seen an implementation in JavaScript here (the parametric system is "Sierpinsky 2"), but in JavaScript functions can be created dynamically as objects (or something like that..), and I can't do that on Processing. So creating a rule to go from F(t) to F(t-1) (and after comparing t>0!) is a bit complicated with the standard string-replacement approach.

I suppose I could create objects for "syllables", and have these objects create other objects, but then I'd have to hard-code each object and rule, and they consume a LOT more memory than a simple string.

Any ideas
Re: parametric L-system
Reply #1 - Mar 13th, 2010, 11:39am
 
Just a quick note: Java comes with a JavaScript interpreter (Rhino) out of the box, as default language for its script framework.
Re: parametric L-system
Reply #2 - Mar 13th, 2010, 11:49am
 
Hm, awesome.

http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29

So, this should work in processing? I'll give it a try then, thanks a lot.

--

edit: Wheee, it does! Needs some minor changes to work on Processing, but it's a charm. Will try that and the L-System code found, let's hope I can get both my existing Processing code (for which I want to use the LSystem) and JS to interact. Probably will use JS just to implement the L-System rules, and pass it as a string to the rest of the application.
Re: parametric L-system
Reply #3 - Mar 15th, 2010, 3:14am
 
The sierpinski rules are very much suited to rendition by context free tools such as http://www.contextfreeart.org/ there are 23 examples with the sierpinski tag in the gallery... Here is one of the briefest it all happens in the last line. Cheesy
Code:
startshape pop

rule pop {
    TRIANGLE{flip 0}
    TRIANGLE{flip 0 b 1 s 0.999}
    3* {r (360/3)} pop{s .5 y .58}
}

cfdg rules are noted for their brevity s = size, b = brightness, r = rotate (degrees)
or there is even ruby processing context free DSL http://github.com/jashkenas/context_free version.  
Heres a fractal with some parametric l-system rules in processing.
http://martinpblogformasswritingproject.blogspot.com/2010/01/simple-fern-fractal...
Page Index Toggle Pages: 1