Java 7 for Absolute Beginners

(nextflipdebug5) #1

CHAPTER 14 ■ RECURSION


■ Note The code for drawTriangle could be made simpler by starting at the outermost layer and counting
backwards. However, I wanted to have a maxLevel value to make setting the depth as easy as possible. I also
used Point2D rather than Point to obtain a greater level of accuracy (and thus prevent small mismatches in the
positions of the triangles within the window).

Finally, here's the result of my SierpinskiTriangle program:

Figure 14-2. Output from the SierpinskiTriangle Program
Free download pdf