On this page:
turtle-state?
make-turtle
starting-turtle
draw
insert-pict
set-rendering-config!

9 3D L-system turtles

 (require lindenmayer/3d-turtle) package: lindenmayer

lindenmayer/3d-turtle provides following symbols for L-system interpretation:

F : Move the turtle forward, and draw a line. If passed an argument it will move that distance, otherwise it will move 1 unit. If within a set of |{| |}|, record a point in the polygon.

f : Like F but does not draw a line.

G : Like F but does not record a point in a polygon.

|.| : Record a point in the polygon if within |{| |}|.

+ : Yaw the turtle clockwise (Rotate around its “up” axis). If a parameter is given it rotates by that many degrees, otherwise it uses the variable δ.

- : Like + but rotates counterclockwise

& : Pitch the turtle clockwise (Rotate around its “left” axis). If a parameter is given it rotates by that many degrees, otherwise it uses the variable δ.

^ and : Like & but counterclockwise.

|\| : Roll the turtle clockwise (Rotate around its “forward” axis). If a parameter is given it rotates by that many degrees, otherwise it uses the variable δ.

/ : Like |\|, but counterclockwise.

$ : Roll the turtle so that its “left” vector is in the X/Y plain.

! : Change the current line width. If a parameter is given it is set to that, otherwise, the line width is decreased by 40%.

|[| : Save the current turtle state.

|]| : Restore the turtle to the state of the most recent |[|.

|{| : Begin recording vertices for a polygon.

|}| : End recording a polygon. The points recorded between this and corresponding |{| are interpreted (and therefore draw), in order, as the boundary of a convex surface. The surface does not need to be planar. The color of the polygon is controlled by a linear interpolation of the color of each vertex.

|'| and : Increment the position in the color vector, modulo its length. (See draw). The colors controls the line color and the colors of the vertices of polygons.

The library also provides the following functions for creating start and finish functions, or building new symbols for the L-system:

procedure

(turtle-state? it)  boolean?

  it : any/c
Determines if it is a turtle state.

procedure

(make-turtle start forward up [line-width])  turtle-state?

  start : dir?
  forward : dir?
  up : dir?
  line-width : positive? = 1/4
Construct a turtle who starts a start, is facing forward, and who’s up is up, with an initial line width of line-width.

up and forward must be unit vectors that are orthogonal to each other.

A turtle at (0,0,0), facing up the z axis, with the x axis up, and a line width of 1/4

procedure

(draw turtle [color-vec])  pict3d?

  turtle : turtle-state?
  color-vec : (vector/c rgba?) = (vector (rgba "white" 0))
Draw the current turtle to a pict3d. The color-vec controls how |'| and are interpreted, with the initial position in the vector being 0.

procedure

(insert-pict turtle pict)  turtle-state?

  turtle : turtle-state?
  pict : pict3d?
Inserts the given pict at the turtles current location and orientation.

procedure

(set-rendering-config! width    
  height    
  [#:ambiance? ambiance    
  #:background background    
  #:emit emit])  void?
  width : positive?
  height : positive?
  ambiance : any/c = #f
  background : rgba? = (rgba "white" 0)
  emit : emitted? = default-emitted
Wraps many of the rendering parameters in pict3d for ease of use. width and height control the width and height of the pict3d. ambiance controls whether or not there is ambient lighting. background sets the background color. emit controls the emitted parameter of all pict3d?s rendered.