Designing a recursive objectTopDrawing targets

Drawing targets

Let's next look at the case of building interesting pictures using recursion. Our first project will be to draw targets. We will look at this process recursively. A target consists of an outer ring with a slightly smaller target inside. When it gets small enough, the target consists of just the outer ring. However, because we need to have a value for the inner target we define something called an emptyTarget. It has type Target, but doesn't actually drawn anything. See the definitions in TargetApp.

While you could probably figure out how to draw a target with a while loop, you do not yet know how to keep track of all of the pieces so they can be dragged around. (Later we will see how to do this with arrays.)

Instead our solution involved defining a type (Target), the trivial object emptyTarget, and a class that implements more complex targets: RingedTarget. RingedTarget represents a recursive data structure because it has an instance variable referring to the same type of object as the class implements.


Designing a recursive objectTopDrawing targets