1 Traditional Turtles
(require graphics/turtles) | package: htdp-lib |
To use any of the turtle drawing functions, you first need to initialize the turtles by calling (turtles #t).
procedure
(move-offset h v) → void?
h : real? v : real?
procedure
(draw-offset h v) → void?
h : real? v : real?
procedure
(erase-offset h v) → void?
h : real? v : real?
procedure
(turn/radians theta) → void?
theta : real?
syntax
(split expr ...)
(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.
syntax
(split* 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)))
syntax
(tprompt expr ...)
For example
moves a turtle forward 100 pixel while drawing a line, and then moves the turtle be immediately back to its 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.
procedure
(save-turtle-bitmap name kind) → void?
name : (or/c path-string? output-port?) kind : (or/c 'png 'jpeg 'xbm 'xpm 'bmp)
1.1 Examples
(require graphics/turtle-examples) | package: htdp-lib |
The graphics/turtle-examples library’s source is meant to be read, but it also exports the following examples. To display these examples, first initialize the turtle window with (turtles #t).
procedure
(regular-poly sides radius) → void?
sides : exact-nonnegative-integer? radius : real?
procedure
(regular-polys n s) → void?
n : exact-nonnegative-integer? s : any/c
procedure
(radial-turtles n) → void?
n : exact-nonnegative-integer?
procedure
(spaced-turtles n) → void?
n : exact-nonnegative-integer?
procedure
(gapped-lines) → void?
procedure
(spyro-gyra) → void?
procedure
(graphics-bexam) → void?
value
procedure
sierp-size : real?
procedure
(sierp-nosplit sierp-size) → void?
sierp-size : real?
procedure
(koch-split koch-size) → void?
koch-size : real?
procedure
koch-size : real?
procedure
procedure
fern-size : exact-nonnegative-integer?
procedure
fern-size : exact-nonnegative-integer?
For fern1, you will probably want to point the turtle up before running this one, with something like:
(turn/radians (- (/ pi 2)))
For fern2, you may need to backup a little.