Create a Processing project RecursiveTree
that draws a tree recursively.
Use the pseudocode main program here (that will require some completion) along with the PTurtle
class to draw a recursive tree.
/**
* This RecursiveTree program uses the Processing library and a
* PTurtle class to draw trees recursively.
*/
// declares instance variables for the main()
// Just a Turtle object
PTurtle t;
void setup() // initializes the screen and turtle
{
size(700, 700);
background(#ffffff);
t = new PTurtle(0, 0);
t.penUp();
t.moveTo(width/2, height -20);
t.left(90); // facing "up"
t.penDown();
}
/**
* The branch() method recursively creates a pair of branches extending out
* from the current one at some angle.
* @param lineLength the length of this branch in pixels
*/
void branch(float lineLength)
{
// basecase - if lineLength is less than some value, return
if
// recursive calls
else
{
// draw line of given length using forward command
// turn right some number of degrees (20?)
// recursively call branch
// turn left some number of degrees (40?)
// recursively call branch
// turn right some number of degrees (20?)
// back up the turtle to the beginning of the line using back command
// return
}
}
// The main draw() loop. Ordinarily, this would be run
// over and over, but here, with a noLoop at the end, it
// only runs once.
void draw()
{
branch(100);
noLoop();
}