simple-graphics - Turtle graphics for teaching programming

Description

A simple turtle graphics system for Chicken. The design goal is to allow people to start drawing pictures in Scheme without distracting boilerplate, like in the good old days of 8-bit micros. This allows for introductory programming exercises that give the reward of drawing pictures, rather than more abstract mathematical or "Hello, World!" problems.

The Turtle

In simple-graphics, you draw pictures by giving instructions to a turtle who lives in a window that will pop open on your screen. She's carrying a pen in her mouth, so she draws a line as she crawls unless you ask her to lift the pen up. And she's got a few different coloured pens on her back.

The turtle starts off in the middle of the window, pointing upwards, with the black pen down, and she crawls at ten pixels per step.

She can be made to go faster or slower than she currently crawls, or told to go at a specific speed. The normal speed of ten pixels per step is speed "1".

If you tell her she's going on an adventure, she remembers where she starts, and when the adventure is over, she returns to where she was when she started (no matter how lost she is at the end of the adventure; she's a homing turtle). You can have little adventures within big adventures, too.

Command Reference

[procedure](forward steps)[procedure](forwards steps)

Moves forward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.

[procedure](backward steps)[procedure](backwards steps)

Moves backward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.

[procedure](left #!optional angle)

Turns left by the indicated angle, which defaults to 90 degrees.

[procedure](right #!optional angle)

Turns right by the indicated angle, which defaults to 90 degrees.

[procedure](turn direction angle)

Turn in the specified direction (left or right) by the specified angle.

[procedure](pen-up)

Lifts the pen up; no drawing will happen until the pen is again lowered.

[procedure](pen-down)

Lowers the pen to the paper, so lines will be drawn when the turtle moves.

Switches to a lighter or darker version of the current pen. Note that making the pen darker and then lighter again does not get you back to the same colour. Too many darkens will quickly get you to black, and too many lightens will quickly get you to white, so you probably only want a single darken or lighten after choosing a named pen colour!

[procedure](faster #!optional factor)

Makes the turtle go faster, by multiplying her current speed by the factor. The default is to double the speed.

[procedure](slower #!optional factor)

Makes the turtle go slower, by dividing her current speed by the factor. The default is to half the speed.

[procedure](home)

Ends all current adventures the turtle is on, and returns her to her home position, the middle of the screen, facing upwards; she switches back to the black pen, lowers it to the paper, and returns to the initial speed of ten pixels per step.

[procedure](clear)

Replaces the paper with a fresh sheet, and sends the turtle back home as per the previous command.

[procedure](save)

Saves your current picture. The first time you do this, the turtle will ask you your name. When the picture is saved, it will tell you the file name it saved it as.

[procedure](goto x y)[procedure](go-to x y)

Teleports the turtle to a given position on the screen, in pixels. 0 0 is the middle of the screen; increasing x goes right, increasing y goes up.

[procedure](heading angle)

Turns the turtle to point towards the indicated heading. 0 is up, 90 is right, 180 is down, 270 is left.

[procedure](speed step-size)

Tells the turtle to walk at the specified speed; a step-size of 1 indicates the default of ten pixels per step.

[syntax](adventure <body>...)

Tells the turtle that the instructions in the <body>... are an adventure; at the end of the adventure, she is to restore her position, heading, pen colour, and pen up/down status to those at the beginning of the adventure.