Eric Roberts - Stanford University
TurtleGraphics assignment, students build
part of a microworld interpreter that supports drawing pictures by
moving a “turtle” around the graphics window.
Programs for the turtle consist of strings of simple commands, such as
F10 (which moves the turtle forward 10 pixel units)
R90 (which rotates the turtle 90 degrees to the
Unlike more traditional uses of turtle graphics in first-year
TurtleGraphics assignment focuses less
on graphics than it does on string manipulation.
The code to implement the graphical user interface is provided as part
of the assignment.
The students are responsible for the string processing that goes into
parsing the programs, executing the individual operations, and
implementing a general find-and-replace mechanism.
That find-and-replace mechanism gives the
TurtleGraphics application the power of a Lindenmayer system,
which supports the creation of complex patterns through repeated string
Lindenmeyer systems allow students to draw fascinating recursive
diagrams without having to use recursion in their implementation.
As an example, the following screenshot shows the
TurtleGraphics application after drawing a Koch
snowflake of order 3:
The program starts out with code to draw a simple triangle, but becomes a fractal pattern after three global string replacements, each of which is similar to the replacement pattern at the lower right of the screenshot.
TurtleGraphicsAssignment.pdf - Assignment Handout
TurtleGraphics.pptx - Slides about this assignment (Eric's Nifty SIGCSE talk)
TurtleGraphicsStarterFiles.zip - Starter files for the assignment
|Summary||Students implement the string processing components of a turtle graphics microworld in which programs are extended using successive replacements in the manner of Lindenmayer systems.|
||String processing, implementing a tokenizer class, stepwise refinement, generating recursive patterns through iterated replacement.|
||Students in the middle of CS 1, after they have learned about string processing.|
||Students can generate amazing fractals diagrams including Koch snowflakes, Sierpinski triangles, and fractal approximations of plant growth without having to understand recursion in depth. The assignment provides students with significant practice using strings and forces them to implement a specialized tokenizer class. The assignment also offers extensive opportunities for extensions and serves as the basis for a contest that encourages highly motivated students to exercise their creativity.|
||Students sometimes feel that the code they write themselves, which focuses on the string processing necessary to implement the application, is less exciting than the graphical parts of the assignment, which are provided to them.|
||Works well with the ACM Graphics Library but does not require it.|
||Several extensions are described in the assignment handout for students who want to push themselves beyond the minimum requirements.|
Extra info about this assignment: