CSC 210 Program #1Recursive trees |
|||||||||||||||||||||||
LogisticsDetails, schmetails...
We'll get back in the saddle of Java GUI programming with Program #1. I hope to get y'all in a Java development groove using: jGRASP, swing, applets, javadoc, HTML, etc. DescriptionIn Program #1, we're going to draw some recursive trees, like this one: Starting with the trunk, each branch spawns two new branches just like itself, but with the following changes:
The tree example above has an order or recursive depth of 5... notice the 5 levels of branches. BTW, also notice that the tree is symmetric. The lengthFactor is 0.80 and the angleDelta is 33 degrees. Pseudo-code for the recursive tree algorithm is:
To satisfy your right-brain on this program, please use the Random class to add some randomness to your trees. Some ideas:
It's up to you. Also, if you get ambitious (or tired of changing parameters in your main program all the time), then you can add GUI objects to your program to change the tree interactively. ImplementationSo how do we do all this? Well, we're going to discuss this in class. We'll touch on:
One of the things that you'll have to do is convert from degrees to radians because degrees (like 45 degrees) work with polar coordinates and radians work with our good, old Cartesian (x,y) coordinate plane. Here's a little method, degreesToRadians(), that you'll need for this translation:
GradingBy the due date, please place your work for Program #1 in your folder on the k: drive. I'll be looking for:
Of course, your code must be beautiful and follow the class coding guidelines. Code that does not meet this metric will be served a harsh brand of grading justice. EtcI will be helping you more on this program, as it is our first. Along those lines, look in the k: drive common_area for:
This program is somewhat similar to the Koch snowflake in your 161 text, Lewis & Loftus (L&L), page 596. There's a nice description of the Random class with a couple of examples in L&L, page 124. I liked the simplicity of the Applet shown on page 96 of L&L. Appendix C in our text was a nice overview of graphics programming in Java, but it's overkill for Program #1. The classes I use are: JPanel, JApplet, JFrame, Graphics, and Color. As an aside, I'm currently thinking that we'll have 5 programs this term at 4 points a pop. They should all be small/medium-sized... though probably a little larger than this one. Enjoy! Apr 5, 2006 Hey the line in the pseudo-code above for the recursive tree algorithm:
should read:
The recursive calls to rtree() in the pseudo-code do this correctly. thanks... yow, bill |
...