Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Racket

Turtle

In preparation of the turtle system's use please download the file racketturtle.rkt and save it in your current working directory. Create a new file, copy and paste the code below to the very beginning of that file, and subsequently save it.

#lang racket
(require "racketturtle.rkt")
(define width 800)   ; determines the window’s size (turtles’ playground)
(define height 800)
(define dc (start width height))

(define bobby (new turtle%
                    [tname ’Bob]
                    [xpos 400][ypos 500][direction 90]
                    [tcolor "YellowGreen"]
                    [tdc dc]))

(send bobby show!)

Now you are ready to develop your procedures. The commands an arbitrary turtle understands are shown below. Syntactically, each turtle instruction matches the following pattern:

(send <turtle> <command> [<parameter>])

Command The command's meaning
say-your-namedisplays the full name of the turtle as initially given.
show!shows the turtle at the current position.
hide!The turtle disappears (from our sight only).
crowThe turtle crows which sounds like wringing a bell.
sleep nThe turtle sleeps for n milliseconds.
forward! nThe turtle moves n steps following the current viewing direction.
backward! nThe turtle moves n steps back following the opposite viewing direction.
right! nThe turtle turns to the right by an angle of n degree.
left! nThe turtle turns to the left by an angle of n degree.
pen-up!causes the turtle to stop tracing beginning at the current position.
pen-down!causes the turtle to continue tracing beginning at the current position.
pen-erase!substitutes an eraser for the turtle's pen.
set-turtle-color! cchanges the turtle's color to c; possible values for c.
set-pen-color! cchanges the turtle's pen color to c; possible values for c.
clonecreates a clone of the turtle.
See some examples in racketturtle-examples.rkt.

About

Racket code for teaching purposes

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages