Turtle Graphics Logo Program

Warning: this simple program produces mesmerizing spirographic images that seem hallucinatory in nature! Discretion is advised! Do not drive while watching these graphics!

Almost 30 years ago, I had heard about a concept developed by Professor Seymour Pappert at MIT that would make it easier for children to write computer programs. The idea was quite simple. Imagine a turtle sitting in the middle of a large piece of paper. He has a pen and is very fast. You can move the turtle with simple commands, like Go Forward, Put the Pen down. Turn Left.

When I bought my first IBM PC in 1981, I wrote a program (using the DeSmet C compiler: anybody remember that? Quite a good product!) that drew a turtle and followed simple commands. This was in the days before Graphical User interfaces, so the turtle preceded the mouse<g>.

More recently, my 9 year old daughter has been enjoying playing computer games, and I helped her create her own. In an hour, I showed her how easy it was to create a bouncing ball on the screen (using a Fox form), with a paddle that could be moved to control the ball. We added some score keeping and thus a game was born.

With her enthusiasm in mind, I dusted off the C source code for my decades old Logo program. I remember the hardest thing was to come up with the coordinates of the turtle, so it looked at least somewhat realistic. I borrowed the same turtle coordinates and came up with the new Logo program.: the FoxPro and Visual Basic versions are available, each about 300 lines of code. Which one goes faster for you?

The turtle accepts single character commands. These commands are executed immediately and are stored as a “program” and can be executed.

Try a simple series of commands: type “f” to go forward, “r” to turn right.

For some psychedelics, try “fr+c.” which means Forward, Right, Increment step, Change color, repeat” (repeat is the period at the end of the string.)

You’ll notice that there is some bounds checking: if the turtle goes out of bounds (or every 1000 iterations) the turtle will reset, repeat, but with the Angle and Step increments changed slightly.

You can store a sequence in one of 10 command slots.

For example, “fr+s” stores the sequence Forward, Right, Increment in Slot 1.

Then you can execute that slot with “x” or do it 44 times with 44nx

Erase, then store “fra2s” will store Forward, Right, Increment Angle, store in slot 2.

Here’s the help text:

            f = Move Forward the Stepsize (*)

            r = turn Right

            l = turn Left

            p = Pen Up (off the paper) or down

            h = Hide turtle

            e = Erase and start over (prerecorded programs survive)

            + = Increase the turtle's step size for Forward

            - = Decrease the step size

            a = Increase the angle for left/right

            . = Repeat current command indefinitely

            q = Quit out of program

            c = Change Color (*) InputValue

            d = Delay (*)

            n = Number for User Parameter. Used for 'x'

            s = Store (*) cmd. Inputvalue indicates which storage cell (1-9)

            x = Execute stored program (*) User parameter times

            [0-9] = input integer into Input value (defaults to 1)

            ? = Show this help text

            [any char] while executing will stop turtle

            * = command will use the Input value for parameter

Upon first sight of the program, my daughter said the red turtle should be green! After showing her Forward and Left, my daughter played with the program: she immediately tried to write out text and found another bug: I was setting the Caption of the window to be the recorded commands, and it became too long, causing an error.

My 3 year old son also had fun with the turtle: he liked moving it around, turning, going out of bounds.

If you come across an interesting logo command, please share it with others in the comments below.

It would be interesting to compare the performance of these with a C++ implementation.

For other computer games, see Create your own typing tutor! and Create your own Word Search puzzles