source: project/wiki/eggref/4/simple-graphics @ 27032

Last change on this file since 27032 was 27032, checked in by Mario Domenech Goulart, 9 years ago

simple-graphics (wiki): _really_ fix link markup

File size: 5.8 KB
Line 
1[[tags: egg]]
2
3== simple-graphics - Turtle graphics for teaching programming
4
5[[toc:]]
6
7=== Description
8
9A 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.
10
11=== Code repository
12
13The source code for simple-graphics is hosted in Fossil at [[http://www.kitten-technologies.co.uk/project/simple-graphics]].
14
15=== Author
16
17[[/users/alaric-blagrave-snellpym|Alaric Snell-Pym]]
18
19=== Requirements
20
21Requires the [[doodle]], [[miscmacros]] and [[parley]] extensions.
22
23=== Quick Start
24
25<enscript highlight="scheme">
26(use simple-graphics)
27
28(forward 10)
29(right)
30(forward 10)
31(right)
32(forward 10)
33(right)
34(forward 10)
35
36(clear)
37
38(red) (forward 1) (right 10)
39(green) (forward 1) (right 10)
40(blue) (forward 1) (right 10)
41(orange) (forward 1) (right 10)
42(yellow) (forward 1) (right 10)
43(brown) (forward 1) (right 10)
44(purple) (forward 1) (right 10)
45(turquoise) (forward 1) (right 10)
46(grey) (forward 1) (right 10)
47(black) (forward 1) (right 10)
48(pen-up) (backward 8) (left 80)
49
50(pen-down) (forward 10)
51
52(save)
53</enscript>
54
55=== The Turtle
56
57In 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.
58
59The turtle starts off in the middle of the window, pointing upwards, with the black pen down, and she crawls at ten pixels per step.
60
61She 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".
62
63If 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.
64
65=== Command Reference
66
67<procedure>(forward steps)</procedure>
68<procedure>(forwards steps)</procedure>
69
70Moves forward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.
71
72<procedure>(backward steps)</procedure>
73<procedure>(backwards steps)</procedure>
74
75Moves backward the indicated number of steps. If the pen is down, then a line will be drawn with the current pen.
76
77<procedure>(left #!optional angle)</procedure>
78
79Turns left by the indicated angle, which defaults to 90 degrees.
80
81<procedure>(right #!optional angle)</procedure>
82
83Turns right by the indicated angle, which defaults to 90 degrees.
84
85<procedure>(turn direction angle)</procedure>
86
87Turn in the specified direction (left or right) by the specified angle.
88
89<procedure>(pen-up)</procedure>
90
91Lifts the pen up; no drawing will happen until the pen is again lowered.
92
93<procedure>(pen-down)</procedure>
94
95Lowers the pen to the paper, so lins will be drawn when the turtle moves.
96
97<procedure>(red)</procedure>
98<procedure>(green)</procedure>
99<procedure>(blue)</procedure>
100<procedure>(orange)</procedure>
101<procedure>(yellow)</procedure>
102<procedure>(brown)</procedure>
103<procedure>(purple)</procedure>
104<procedure>(turquoise)</procedure>
105<procedure>(grey)</procedure>
106<procedure>(black)</procedure>
107
108Switches to a different coloured pen.
109
110<procedure>(lighter)</procedure>
111<procedure>(darker)</procedure>
112
113Switches 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!
114
115<procedure>(faster #!optional factor)</procedure>
116
117Makes the turtle go faster, by multiplying her current speed by the factor. The default is to double the speed.
118
119<procedure>(slower #!optional factor)</procedure>
120
121Makes the turtle go slower, by dividing her current speed by the factor. The default is to half the speed.
122
123<procedure>(home)</procedure>
124
125Ends 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.
126
127<procedure>(clear)</procedure>
128
129Replaces the paper with a fresh sheet, and sends the turtle back home as per the previous command.
130
131<procedure>(save)</procedure>
132
133Saves 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.
134
135<procedure>(goto x y)</procedure>
136<procedure>(go-to x y)</procedure>
137
138Teleports 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.
139
140<procedure>(heading angle)</procedure>
141
142Turns the turtle to point towards the indicated heading. 0 is up, 90 is right, 180 is down, 270 is left.
143
144<procedure>(speed step-size)</procedure>
145
146Tells the turtle to walk at the specified speed; a step-size of 1 indicates the default of ten pixels per step.
147
148<syntax>(adventure <body>...)</syntax>
149
150Tells 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.
151
152== Release
153
154* 0.2: Minor packaging improvements, and more colours!
155* 0.1: Initial public release
156
157== License
158
159See [[http://www.kitten-technologies.co.uk/project/simple-graphics/doc/trunk/LICENCE.txt|the BSD-style licence]] simple-graphics is available under.
Note: See TracBrowser for help on using the repository browser.