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 › [Beginner] First L-System "Algae" sketch
Page Index Toggle Pages: 1
[Beginner] First L-System "Algae" sketch (Read 1061 times)
[Beginner] First L-System "Algae" sketch
Jan 23rd, 2009, 12:17am
 
In the course of learning programming I stumbled upon the L-System. And seeing I was nearly "done" with chapter 9 (Arrays) of Shiffman's book, I took up the challenge to write a simple program which produces the simple L-System Algae.

Arrays somehow gave me a lot of fuss, and eventually I ended up with using ArrayList (somehow much more intuitive).

So after several headaches, I feel proud to show you my ABABBABABABBAB producing L-System Smiley. Hope to add some visual feedback soon, not sure yet how or what.

I have commented heavily for other beginners to examine, and perhaps some more advanced programmers can give some feedback.

Thanks in advance.

http://www.openprocessing.org/visuals/applets/visual4598d85c91f0c0d8b582a88ff413ef5c/

P.S.: Ignore all the PFont() stuff, I added it in since applets don't show println() results. Doh!
Re: [Beginner] First L-System "Algae" sk
Reply #1 - Jan 23rd, 2009, 2:20pm
 
I might take a look later.
Just a quick word to tell you that println() result can be seen even within applets: you can see them in the Java console.
On Windows XP, I can access the Java console by right-clicking on the tray area icon that appears when an applet is launched. You can see there if there are exception, reset the cache (useful when you update your jar), etc.
Re: [Beginner] First L-System "Algae" sk
Reply #2 - Jan 24th, 2009, 12:51am
 
Ah, I see that's good to know. And If you happen to have the time to look at my code, don't hold back any criticism. Somehow it still feels a bit messy and inefficient.
Re: [Beginner] First L-System "Algae" sk
Reply #3 - Jan 24th, 2009, 6:26am
 
Nothing looks terribly inefficient at a 2sec glance.  Just wanted to pop in and say keep up the learning and good work!
Re: [Beginner] First L-System "Algae" sk
Reply #4 - Jan 24th, 2009, 10:27am
 
@ilazarte

Thank you, and certainly will.
Re: [Beginner] First L-System "Algae" sk
Reply #5 - Jan 24th, 2009, 4:10pm
 
OK, I look at your code, which seems OK (I am not specialist of L-systems...). I will just make some minor comments on style. Smiley

int iterations = 9;
I like to add final to such constant, precisely to show they are constants, and avoid accidental change and such.
Not really needed for such simple code, but at good habit to take.

setup
The reference insists on making size() call the first one, because code before it might be executed twice. Don't ask me why! Wink

if(result.stat == true)
Mmm, personally, I dislike checking a boolean for true or false, I feel it is redundant. Some of my co-workers disagree... Smiley Now, I try and give more explicit names to boolean variables: "stat" doesn't "speak", I can't see at a glance if that's status, state, statistic...
I would write something like: if (result.isSet) for example.

if(result.stat == false)
Grrr! Wink Just put else there! If it is not true, it is necessarily false! :-D

String t = "A";
nresult = nresult + t;

Sometime, particularly for creation of complex objects, I like to make intermediary variables like that. Here, it is a bit of an overkill, a nresult += "A"; would have been enough.

buffer.clear();
No need to clear a buffer newly created (thus already empty).

I criticized style over content, I fear... :-D
I think you could have stored "A" or "B" in AB class instead of true/false, for example, but it might depend on how you want to make the program evolve.
Re: [Beginner] First L-System "Algae" sk
Reply #6 - Jan 25th, 2009, 9:51pm
 
Thanks for the great tips, glad to see I'm not entirely off in my programming. Tongue
Page Index Toggle Pages: 1