[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.35 Turtle graphics

Procedures for turtle graphics like LOGO.

For example, the following code paints Koch curve.

(define w (make-window-frame 600 600 -1 -1 21 21))
(define t (make-turtle w 0 0))

(define (koch len times)
  (if (= times 0)
    (turtle-draw t len)
    (begin
      (koch (/ len 3.0) (- times 1))
      (turtle-turn-right t 60)
      (koch (/ len 3.0) (- times 1))
      (turtle-turn-left t 120)
      (koch (/ len 3.0) (- times 1))
      (turtle-turn-right t 60)
      (koch (/ len 3.0) (- times 1)))))

(koch 20 7)
Function: make-turtle frame init-x init-y [turtle-image]

creates a turtle.
frame specifies a frame to draw a turtle, init-x and init-y specify a initial coordinate of the turtle and turtle-image specifies an image of the turtle.
The default image is used if turtle-image is not specified.

Function: turtle-draw turtle length

draws a line whose size is the given length along current direction.

Function: turtle-turn-left turtle degree
Function: turtle-turn-right turtle degree

rotates the turtle to left(right).

Function: turtle-move turtle length

moves the turtle along current direction without drawing.

Function: turtle-change-color turtle color

changes the color in which the turtle draws.

Function: turtle-clear turtle

clears what the turtle has been drawn.

Function: turtle-undo turtle

undoes one action which the turtle has been drawn.

Function: turtle-hide turtle
Function: turtle-show turtle

hides(shows) the turtle.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 9, 2012 using texi2html 5.0.