# 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

Tags

1. Hi Calvin,

Logo was one of the first programming languages I had contact with. During this time my parents bought a Joyce (Amstrad PCW 8512) and so I could experiment with Logo on CP/M+ OS. It was quite funny to produce those Lissajou graphics.

It’s fun to see this stuff in VFP today.

Kind regards, JoKi

2. Calvin_Hsia says:

The Fox and VB versions of the turtle don’t show the same color because the order of RGB is a little different. Red is the low order 8 bits of the color in the Fox version, but the 3rd byte in the VB version.

Add these lines to make them the same.

Dim n As Integer

n = ((Me.oColor.R + Me.oColor.G * 256 + Me.oColor.B * 256 ^ 2) + nInputParam) And &HFFFFFF

Me.oColor = Color.FromArgb(&HFF000000 Or ((n And &HFF) * 256 ^ 2 + (n And &HFF00) + (n And &HFF0000) / 256 ^ 2))

Also, the Fox version always started with the same color after the turtle went out of bounds. The version available now on the website fixes that by saving/restoring the color around the call to InitVals.

3. Ael loved playing with the turtle. 🙂 Thanks!

4. AYESHA says:

1.  FD 30  RT 90  FD 30  RT 90

FD 30  RT 90  FD 30  RT 90

2.  BK  30  RT 90  LT  135  FD 30

5. Sometimes friends or relatives might hear that you’re an expert with using computers, and might ask you

6. Peter Herzog says:

Hi Calvin

What a nice idea. Falling back in my past … 🙂

My first "try" ended in a fractal mandelbrot picture.

Greetings from germany

7. abhirami says:

hi,my name is abhirami.i love computer. yesterday i learnt introduction to Logo.teacher said who has   computer at home,do Logo strictly,so please.

8. abhirami says:

hi,my name is abhirami.i love computer. yesterday i learnt introduction to Logo.teacher said who has   computer at home,do Logo strictly,so please.

9. Olgunka-iq says:

<a href= http://index4.22tjol.com >cathy the cake lady</a> <a href= http://index3.22tjol.com >middlesex hospital middletown ct.</a> <a href= http://index1.22tjol.com >woman on a bar stool</a> <a href= http://index5.22tjol.com >sensuous tickling videos</a> <a href= http://index2.22tjol.com >babessites.info</a>

10. yavuz says:

hi;

i want to write a simple turtle graphics program.

your project is so good. i want to do like this but adding a command line(textbox) then work from command line.

sorry for my english 🙁

how can i do, adding a command line ?