TopDesigning a recursive objectMore examples of recursion

More examples of recursion

See the definitions in Scribble and SingleScribbler for a program that not only allows you to draw scribbles, but also let you move them, color them, and erase them. This also uses a recursive data structure, built from a base class of emptyScribble and a recursive case of scribble.

Notice that selecting a color allows the user to change the color of the last scribble drawn. Clicking the erase button erases the last scribble drawn. However, if you click it again, nothing will happen. Notice how emptyScribble is used in SingleScribbler to make sure that currentScribble always has a value.

See the program ChainReaction Click to create a new ball and move the mouse in and out of the window to get the chain reaction.


TopDesigning a recursive objectMore examples of recursion