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 source code for simple-graphics is hosted in Fossil at http://www.kitten-technologies.co.uk/project/simple-graphics.
(use simple-graphics) (forward 10) (right) (forward 10) (right) (forward 10) (right) (forward 10) (clear) (red) (forward 1) (right 10) (green) (forward 1) (right 10) (blue) (forward 1) (right 10) (orange) (forward 1) (right 10) (yellow) (forward 1) (right 10) (brown) (forward 1) (right 10) (purple) (forward 1) (right 10) (turquoise) (forward 1) (right 10) (grey) (forward 1) (right 10) (black) (forward 1) (right 10) (pen-up) (backward 8) (left 80) (pen-down) (forward 10) (save)
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.
- (forward steps) procedure
- (forwards steps) procedure
Moves forward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.
- (backward steps) procedure
- (backwards steps) procedure
Moves backward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.
- (left #!optional angle) procedure
Turns left by the indicated angle, which defaults to 90 degrees.
- (right #!optional angle) procedure
Turns right by the indicated angle, which defaults to 90 degrees.
- (turn direction angle) procedure
Turn in the specified direction (left or right) by the specified angle.
- (pen-up) procedure
Lifts the pen up; no drawing will happen until the pen is again lowered.
- (pen-down) procedure
Lowers the pen to the paper, so lines will be drawn when the turtle moves.
- (red) procedure
- (green) procedure
- (blue) procedure
- (orange) procedure
- (yellow) procedure
- (brown) procedure
- (purple) procedure
- (turquoise) procedure
- (grey) procedure
- (black) procedure
Switches to a different coloured pen.
- (lighter) procedure
- (darker) procedure
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!
- (faster #!optional factor) procedure
Makes the turtle go faster, by multiplying her current speed by the factor. The default is to double the speed.
- (slower #!optional factor) procedure
Makes the turtle go slower, by dividing her current speed by the factor. The default is to half the speed.
- (home) procedure
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.
- (clear) procedure
Replaces the paper with a fresh sheet, and sends the turtle back home as per the previous command.
- (save) procedure
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.
- (goto x y) procedure
- (go-to x y) procedure
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.
- (heading angle) procedure
Turns the turtle to point towards the indicated heading. 0 is up, 90 is right, 180 is down, 270 is left.
- (speed step-size) procedure
Tells the turtle to walk at the specified speed; a step-size of 1 indicates the default of ten pixels per step.
- (adventure <body>...) syntax
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.
- 0.2: Minor packaging improvements, and more colours!
- 0.1: Initial public release
See the BSD-style licence simple-graphics is available under.