On this page:
turtles
move
draw
erase
move-offset
draw-offset
erase-offset
turn
turn/ radians
merge
2.1 Examples

2 Value Turtles

 (require graphics/value-turtles)

The value turtles are a variation on traditional turtles. Rather than having just a single window where each operation changes the state of that window, in the graphics/value-turtles library, the entire turtles window is treated as a value. This means that each of the primitive operations accepts, in addition to the usual arguments, a turtles-window value; instead of returning nothing, each returns a turtles-window value.

(turtles width    
  height    
  [init-x    
  init-y    
  init-angle])  turtles-window?
  width : real?
  height : real?
  init-x : real? = (/ width 2)
  init-y : real? = (/ height 2)
  init-angle : real? = 0
Creates a new turtles window with the given width and height. The remaining arguments specify position of the initial turtle and the direction in radians (where 0 is to the right).

(move n turtles)  turtles-window?
  n : real?
  turtles : turtles-window?
Moves the turtle n pixels, returning a new turtles window.

(draw n turtles)  turtles-window?
  n : real?
  turtles : turtles-window?
Moves the turtle n pixels and draws a line along the path, returning a new turtles window.

(erase n turtles)  turtles-window?
  n : real?
  turtles : turtles-window?
Moves the turtle n pixels and erases a line along the path, returning a new turtles window.

(move-offset h v turtles)  turtles-window?
  h : real?
  v : real?
  turtles : turtles-window?
(draw-offset h v turtles)  turtles-window?
  h : real?
  v : real?
  turtles : turtles-window?
(erase-offset h v turtles)  turtles-window?
  h : real?
  v : real?
  turtles : turtles-window?
Like move, draw, and erase, but using a horizontal and vertical offset from the turtle’s current position.

(turn theta turtles)  turtles-window?
  theta : real?
  turtles : turtles-window?
Turns the turtle theta degrees counter-clockwise, returning a new turtles window.

(turn/radians theta turtles)  turtles-window?
  theta : real?
  turtles : turtles-window?
Turns the turtle theta radians counter-clockwise, returning a new turtles window.

(merge turtles1 turtles2)  turtles-window?
  turtles1 : turtles-window?
  turtles2 : turtles-window?
The split and tprompt forms provided by graphics/turtles isn’t needed for graphics/value-turtles, since the turtles window is a value.

Instead, the merge accepts two turtles windows and combines the state of the two turtles windows into a single window. The new window contains all of the turtles of the previous two windows, but only the line drawings of the first turtles argument.

2.1 Examples

 (require graphics/value-turtles-examples)

The graphics/value-turtles-examples library is similar to graphics/turtle-examples, but using graphics/value-turtles instead of graphics/turtles.