In this exercise you will be making a recursive drawing known as an "H-tree", pictured at right.
Follow these steps:
drawLine(Color, StartX, StartY, EndX, EndY, Thickness);
This draws a line (go figure!) from the starting (x,y) coordinate to
the ending (x,y) coordinate, in the specified color and thickness.
public void draw() {
// All your code goes here
}
currentColor
for the Color parameter to
drawLine().
Once you have completed this, now is a good time to stop, compile, and
run your new program to verify that your 1st line in the tree turns
out. Make an HTML file to view your applet and include:
< applet code = "HTree.class" height = 600 width = 600>
</applet>
currentColor
for the Color parameter to drawLine().
drawLines
you should create and
draw 4 smaller H objects in the correct place, with the correct color
and size. The code for creating and drawing
looks something like this:
HTree UpperRightH = new HTree(Color, X, Y, Size, Angle, Info);
UpperRightH.draw();
Color newColor = nextColor(currentColor);
before your new
statements, and use newColor as the
Color parameter in the new
statement.
currentInfo
.
if
statement that checks to see if the
size is not too small. If you mess up (or omit) your base case,
Netscape will likely crash! If this happens, do not, repeat not, start
the debugger (some dialog box may give you this option). What you want to do is quit and restart Netscape and (of course) repair your base case!
PREVIOUS | 1 | 2 | 3 | 4 | 5 | NEXT |