Using Recursion in GraphicsSerpinsky GasketSlide 3Rendering a Serpinsky GasketSerpinsky DemoClasswork/LabCompSci 629.1Using Recursion in GraphicsRecursion can be a powerful tool Closely related to FractalsSelf-similarity Keep zooming in: still looks the same Can produce very interesting figures with very little inputSerpinsky Gasket is just a lot of trianglesDefine recursivelyCompSci 629.2Serpinsky GasketStart with triangleThen put (1/2 size) triangles within triangleCompSci 629.3Serpinsky GasketContinue process with ¼ sized triangles, etcInsight: use Serpinsky Gaskets instead of trianglesCompSci 629.4Rendering a Serpinsky Gasket Mathematically, Gasket is defined for invinitely small triangle.Goes on foreverZoom in as far as you like: always the same pictureIn drawing a Serpinsky Gasket what are the issues?Time to drawWhat can you seeHow do we handle this potentially infinite recursion?What to use as the base case????CompSci 629.5Serpinsky DemoIn code directoryUsing AppletRun Serpinsky.htmlNote feature to slow down drawingGet betters sense of how recursive calls workAlso see how incredibly fast computer is…Review recursive featuresWhat is done in the base case?What would figure be like if we drew nothing exceptIn the base case?CompSci 629.6Classwork/LabWill be doing two different figures recursivelyTargetCircle ArtFor each, will use 2 approaches1. One Object: Draw RecursivelyOur drawing technique will use recursion2. Object Creates Other Object RecursivelyEach object will create “clone” objects using newEach of smaller size and in different positionsWill invoke the paint methods of these
View Full Document