public void invertTriangles (double size, int number) { System.out.println("invertTriangles("+size+", "+number+");"); if (number>0) { // base case equiTriangle(size); // draw the outer triangle moveToNextTriangle(size/2); // move in position to draw the next triangle pattern invertTriangles(size/2, number-1); // draw next pattern returnToStart(size/2); // meet invariant: start and end in same place } }
// draws an equilateral triangle with sides of the specified size public void equiTriangle (double size) { System.out.println("equiTriangle size "+size); fd(size); lt(120); fd(size); lt(120); fd(size); lt(120); }
public void moveToNextTriangle (double distance) { System.out.println("moveToNextTriangle"); fd(distance); lt(60); }
public void returnToStart (double distance) { System.out.println("returnToStart"); rt(60); bd(distance); }