Java Reference
In-Depth Information
drawSierpinski(g, lev - 1, p1, midP1P2, midP3P1);
drawSierpinski(g, lev - 1, p2, midP2P3, midP1P2);
drawSierpinski(g, lev - 1, p3, midP3P1, midP2P3);
}
}
private Point midPoint(Point pOne, Point pTwo)
{
Point mid = new Point((pOne.x + pTwo.x) / 2,
(pOne.y + pTwo.y) / 2);
return mid;
}
}
Sample Run: Figure 13-10 shows a sample run. In this sample run, the user input is
entered in the input dialog box.
FIGURE 13-10 Recursion depth of 4 produces a Sierpinski gasket of order 3
QUICK REVIEW
1 . The process of solving a problem by reducing it to smaller versions of itself
is called recursion.
2 . A recursive definition defines the problem in terms of smaller versions of
itself.
3 . Every recursive definition has one or more base cases.
 
 
Search WWH ::




Custom Search