1 Traditional Turtles
on? : any/c |
Shows and hides the turtles window based on on?. If on? is not supplied, the state is toggled.
n : real? |
Moves the turtle n pixels without drawing.
n : real? |
Moves the turtle n pixels and draws a line on the path.
n : real? |
Moves the turtle n pixels and erase along the path.
| |||
| |||
|
Like move, draw, and erase, but using a horizontal and vertical offset from the turtle’s current position.
theta : real? |
Turns the turtle theta degrees counter-clockwise.
(turn/radians theta) → void? |
theta : real? |
Turns the turtle theta radians counter-clockwise.
Erases the turtles window.
(split expr ) |
Spawns a new turtle where the turtle is currently located. In order to distinguish the two turtles, only the new one evaluates expr. For example, if you start with a fresh turtle-window and type:
(split (turn/radians (/ pi 2)))
you will have two turtles, pointing at right angles to each other. Continue with
(draw 100)
You will see two lines. Now, if you evaluate those two expression again, you will have four turtles, etc.
(split* expr ) |
Like (split expr ), except that one turtle is created for each expr.
For example, to create two turtles, one pointing at π/2 and one at π/3, evaluate
(split* (turn/radians (/ pi 3)) (turn/radians (/ pi 2)))
(tprompt expr ) |
Limits the splitting of the turtles. Beforeexpr is evaluated, the state of the turtles (how many, their positions and headings) is “checkpointed.” Then expr is evaluated, and then the state of the turtles is restored, but all drawing that may have occurred during execution of expr remains.
For example
moves a turtle forward 100 pixel while drawing a line, and then moves the turtle be immediately back to it’s original position. Similarly,
(tprompt (split (turn/radians (/ pi 2))))
splits the turtle into two, rotates one 90 degrees, and then collapses back to a single turtle.
The fern functions below demonstrate more advanced use of tprompt.
1.1 Examples
The graphics/turtle-examples library’s source is meant to be read, but it also exports the following examples.
(regular-poly sides radius) → void? |
sides : exact-nonnegative-integer? |
radius : real? |
Draws a regular poly centered at the turtle with sides sides and with radius radius.
(regular-polys n s) → void? |
s : any/c |
Draws n regular polys each with n sides centered at the turtle.
(radial-turtles n) → void? |
Places 2n turtles spaced evenly pointing radially outward.
(spaced-turtles n) → void? |
Places 2n turtles evenly spaced in a line and pointing in the same direction as the original turtle.
Draws some spokes, using radial-turtles and spaced-turtles.
(spyro-gyra) → void? |
Draws a spyro-grya reminiscent shape.
As the name says...
(graphics-bexam) → void? |
Draws a fractal that came up on an exam that the author took.
A constant that is a good size for the serp procedures.
| ||
|
Draws the Serpinski triangle in two different ways, the first using split heavily. After running the first one, try executing (draw 10).
A constant that is a good size for the koch procedures.
| ||
|
Draws the same Koch snowflake in two different ways.
a : real? |
b : real? |
c : real? |
Watch the Lorenz attractor (a.k.a. butterfly attractor) initial values a, b, and c.
Calls lorenze with good initial values.
| ||
|
Draws the Peano space-filling curve, where peano1 uses split.
A good size for the fern1 and fern2 functions.
| ||
|
For fern1, you will probably want to point the turtle up before running this one, with something like:
(scheme (turn/radians (- (/ pi 2))))
For fern2, you may need to backup a little.