CompSci 629.1Using Recursion in Graphicsÿ Recursion can be a powerful tool ÿ Closely related to Fractals Self-similarity Keep zooming in: still looks the same ÿ Can produce very interesting figures with very little inputÿ Serpinsky Gasket is just a lot of triangles Define recursivelyCompSci 629.2Serpinsky Gasketÿ Start with triangleÿ Then put (1/2 size) triangles within triangleCompSci 629.3Serpinsky Gasketÿ Continue process with ¼ sized triangles, etcÿ Insight: use Serpinsky Gaskets instead of trianglesCompSci 629.4Rendering a Serpinsky Gasketÿ Mathematically, Gasket is defined for invinitely small triangle. Goes on forever Zoom in as far as you like: always the same pictureÿ In drawing a Serpinsky Gasket what are the issues? Time to draw What can you seeÿ How do we handle this potentially infinite recursion? What to use as the base case? ???CompSci 629.5Serpinsky Demoÿ In code directory Using Applet Run Serpinsky.htmlÿ Note feature to slow down drawing Get betters sense of how recursive calls work Also see how incredibly fast computer is…ÿ Review recursive features What is done in the base case?ÿ What would figure be like if we drew nothing except In the base case?CompSci 629.6Classwork/Labÿ Will be doing two different figures recursively Target Circle Artÿ For each, will use 2 approaches1. One Object: Draw Recursively Our drawing technique will use recursion2. Object Creates Other Object Recursively Each object will create “clone” objects using new Each of smaller size and in different positions Will invoke the paint methods of these
View Full Document