Free Online Turtle Graphics : logointerpreter.com - Surf your logo code!
Logo interpreter with animation
Web technologies
   


Please wait,

loading turtle environment...
   
Common Logo Commands
Using simple instructions you will get outstanding programs quickly and easily.
Learn more about your turtle's language - see the full reference [here].


forward expr
fd expr
Description: moves the turtle forward expr pixels, in the direction it is facing.
Examples:
fd 100
fd -50.25
Note that you can use negative values to go backwards.
back expr
bk expr
Description: moves the turtle backward expr pixels, exactly opposite to the direction that it's facing.
Examples:
bk 80
bk -35.75
Note that you can use negative values to go forward.
left expr
lt expr
Description: rotates the turtle expr degrees counterclockwise.
Examples:
lt 90.30
lt -45
Note that you can use negative values to rotate clockwise.
right expr
rt expr
Description: rotates the turtle expr degrees clockwise.
Examples:
rt 120
rt -60
Note that you can use negative values to rotate counterclockwise.
setpos [ expr expr ]
Description: moves the turtle to the specified location without drawing. The input is a list of two numbers, the X and Y coordinates.
Example:
setpos [100 100]
setxy expr expr
Description: moves the turtle to the specified location without drawing. The two inputs are numbers, the X and Y coordinates.
Example:
setxy 100 100
setx expr
Description: moves the turtle horizontally from its old position to a new horizontal coordinate. expr is the new X coordinate.
Example:
setx 150
sety expr
Description: moves the turtle vertically from its old position to a new vertical coordinate. expr is the new Y coordinate.
Example:
sety -220
setheading expr
seth expr
Description: turns the turtle to a new heading. expr is a number, the heading in degrees clockwise from the positive Y axis.
Example:
seth 120
home
Description: moves the turtle to the initial position (canvas center), pointing upwards.
Example:
home
showturtle
st
Description: shows the turtle on the canvas.
hideturtle
ht
Description: hides the turtle from the canvas.
wrap
Description: (default) tells the turtle to enter wrap mode. From now on, if the turtle is asked to move past the boundary of the graphics window, it will "wrap around" and reappear at the opposite edge of the window.
Example: wrap fd 300
The result is shown bellow:
window
Description: tells the turtle that can move past the edges of the screen, unbounded. The visible canvas is considered as just part of an infinite graphics plane; the turtle can be anywhere on the plane.
Example: window fd 300
The result is shown bellow:
If you lose the turtle, home will bring it back to the center of the window.
fence
Description: tells the turtle that it can't move past the edges of the screen. From now on, if the turtle is asked to move past the boundary of the graphics canvas, it will move as far as it can and then stop at the edge.
Example: fence fd 300
The result is shown bellow:

Animation is the process of creating a continuous motion and shape change illusion by means of the rapid display of a sequence of static images that minimally differ from each other.

wait milliseconds
Description: waits a number of milliseconds before executing the next command.
Test the following programs to better understand the wait command.
Example 1:
circle 100
wait 1000
fd 120
circle 50
Example 2:
repeat 10 [
   circle random 40
   wait 500
   print repcount
   cs
]
clean
Description: clears the graphics canvas.
clearscreen
cs
Description: clears the graphics canvas and moves the turtle at the initial position.
This command is the same as clear and home together.

More about the canvas

You can instruct the turtle to draw shapes as it moves on a virtual canvas that you can call it "the turtle space".

The editor's canvas dimensions are: 500 pixels x 500 pixels and the center of your graphic window / canvas
is the initial turtle location [0,0]:

(read more about the cartesian coordinates section here)

As you can see, the turtle is heading North by default:

The turtle space is different from the Cartesian coordinate system that you may be familiar with.
In this system, 0 degrees is aligned with the positive Y axis instead of the positive X axis. The other difference is that angle measurement in positive amounts measure clockwise rotation, the opposite direction that you've learned in math classes.
pendown
pd
Description: sets the pen down and the turtle resumes leaving a trail as it moves on the canvas.
penup
pu
Description: sets the pen up and the turtle stops leaving a trail as it moves on the canvas.
penpaint
Description: (default) sets the drawing mode to PAINT.
penerase
Description: sets the drawing mode to ERASE.
Example:
penerase
setpensize 30
fd 100
The result is shown bellow:
setpencolor color
setpc color
setcolor color
Description: sets the stroke color (default: black). The color can be set using standard color codes or html HEX values:
Examples:
setcolor "red
setcolor "4
setcolor "#ff0000
Standard color codes: 0: "black" (
), 1: "blue" (
), 2: "lime" (
), 3: "cyan" (
), 4: "red" (
), 5: "magenta" (
),
6: "yellow" (
), 7: "white" (
), 8: "brown" (
), 9: "tan" (
), 10: "green" (
), 11: "aquamarine" (
), 12: "salmon" (
),
13: "purple" (
), 14: "orange" (
), 15: "gray" (
).
setpensize value
setwidth value
setpw value
Description: sets the pen size to a number of value pixels.
setbgcolor color
Description: sets the background color of the canvas (note: draws a 500x500px square on the graphics canvas). The color can be set using standard color codes or html HEX values:
Example:
setbgcolor "green
setbgcolor "10
setbgcolor "#00ff00
The result is shown bellow:
Standard color codes: 0: "black" (
), 1: "blue" (
), 2: "lime" (
), 3: "cyan" (
), 4: "red" (
), 5: "magenta" (
),
6: "yellow" (
), 7: "white" (
), 8: "brown" (
), 9: "tan" (
), 10: "green" (
), 11: "aquamarine" (
), 12: "salmon" (
),
13: "purple" (
), 14: "orange" (
), 15: "gray" (
).
setbgimg image
Description: sets a background image using the image name.
Some of the names are: "White", "Beach", "Field", "Winter", "Space", "Scene", etc. You can find all the available images using the Background image panel from the editor:
Example:
setbgimg "Winter
The result is shown bellow:
arc angle radius
Description: draws an arc of a circle, with the turtle at the center, with the specified radius, starting at the turtle's heading and extending clockwise through the specified angle.
Note: the turtle is not moving while drawing the arc.
Example 1:
arc 90 100
Example 2: drawing a circle with a radius of 50 pixels:
arc 360 50
circle radius
Description: draws a circle, with the turtle at the center, with the specified radius.
Note: the turtle is not moving while drawing the circle.
Example:
circle 50
fillcircle radius
Description: fills a circle, with the turtle at the center, with the specified radius.
Note: the turtle is not moving while filling the circle.
Example:
setfillcolor "magenta
fillcircle 50
rect width height rotation
Description: draws a rectangle with the specified width and height and the turtle at the center. If the rotation parameter is set to true, the rectangle is rotated by the turtle's heading.
Note: the turtle is not moving while drawing the rectangle.
Example 1:
left 45
rect 60 100 false
Example 2:
left 45
rect 60 100 true
fillrect width height rotation
Description: fills a rectangle with the specified width and height and the turtle at the center. If the rotation parameter is set to true, the rectangle is rotated by the turtle's heading.
Note: the turtle is not moving while filling the rectangle.
Example 1:
left 45
setfillcolor "cyan
fillrect 60 100 false

Example 2:
left 45
setfillcolor "cyan
fillrect 60 100 true

shadowblur level
Description: sets the blur level for shadows.
Note: the default value of level is 0.
Example:
shadow 10
fillcircle 30
shadowcolor color
Description: sets the shadow color.
Note: the default value of color is "black".
Example:
shadow 10
shadowcolor "magenta
fillcircle 30
shadowoffset x y
Description: sets the horizontal (x) and vertical distance (y) of the shadow from the shape.
Note: the default position of the shadow is exactly under the shape (not visible).
Example:
shadowoffset 10 10
fillcircle 30

About paths. A path consists of a list of zero or more subpaths. Each subpath is a list of one or more points that are connected by straight or curved lines. Each subpath also contains a flag that indicates whether the subpath is closed. If a subpath is closed, the last point of the subpath is connected to the first point by a straight line. Subpaths that have fewer than two points are ignored when the path is painted.

beginpath
Description: begins a new path, or resets the current path.
cancelpath
Description: deletes/cancels the current path.
strokepath
Description: strokes/draws the current path with the current line/stroke color (default black).
fillpath
Description: fills the current path with the current filling color (default white).
setfillcolor color
setfc color
Description: sets the filling color (default: white). The color can be set using standard color codes or html HEX values.
Examples:
setfillcolor "red
setfillcolor "4
setfillcolor "#ff0000
Standard color codes: 0: "black" (
), 1: "blue" (
), 2: "lime" (
), 3: "cyan" (
), 4: "red" (
), 5: "magenta" (
),
6: "yellow" (
), 7: "white" (
), 8: "brown" (
), 9: "tan" (
), 10: "green" (
), 11: "aquamarine" (
), 12: "salmon" (
),
13: "purple" (
), 14: "orange" (
), 15: "gray" (
).

Example 1. The code bellow draws a triangle:

beginpath
fd 100
left 90
fd 100
strokepath

Example 2. The code bellow fills a rectangle:

beginpath
fd 100
left 90
fd 150
left 90
fd 100
setfillcolor "blue
fillpath

Example 3. The code bellow draws and fills a nice flower:

repeat 8 [
   make "c (random 16)
   setfillcolor :c
   beginpath
   repeat 2
   [ repeat 100 [fd 3 rt 1]
   rt 80 ]
   rt 45
   fillpath
]

Note: while drawing paths, the drawing mode is automatically set to "window".
quadcurve cpx cpy epx epy
qc cpx cpy epx epy
Description: moves the turtle on a path described by a quadratic Bézier curve.
The parameters are the coordinates of: the control point (cpx cpy) and the end point (epx epy):

Example:
qc -100 100 220 220
The result is shown below:



(see more info about the Bézier curve on wikipedia.org here)
cubiccurve cp1x cp1y cp2x cp2y epx epy
cc cp1x cp1y cp2x cp2y epx epy
Description: moves the turtle on a path described by a cubic Bézier curve.
The parameters are the coordinates of: the two control points (cp1x cp1y cp2x cp2y) and the end point (epx epy):

Example:
cc 50 200 90 -180 200 -100
The result is shown below:



(see more info about the Bézier curve on wikipedia.org here)
Global variables (input)
You can set two global variables for your program (:lgv1 and :lgv2).
Example:

Warning: You can't change the content of the variable if the program is not empty. Reload it before changing the value.
Comments (for the program). You can write a comment like this:
Example:
;rotating left
left 90
;forwarding 100 pixels
fd 100
;this is a comment which the program will not see
;comments start with a semicolon
Printing (output)
If you mistyped an instruction, you will be automatically warned by a message:

As you can see, the Turtle can transmit messages. So, using the "print" command you can display useful information. Example: you can perform arithmetic calculations very easy:



Drawing text on the canvas (output)
label text
Description: takes a word or list as input, and strokes the input on the graphics canvas, starting at the turtle's position.
Note: The text's color is the stroking color (set it using setpencolor).
Example 1:
label "LOGO
Example 2:
right 90
setlabelheight 40
label [I love logo!]
flabel text
Description: takes a word or list as input, and fills the input on the graphics canvas, starting at the turtle's position.
Note: The text's color is the filling color (set it using setfillcolor).
Example 1:
right 90
setlabelheight 40
setfillcolor "red
flabel "LOGO
Example 2: You can use both commands when drawing a text:
right 90
setlabelheight 40
setfillcolor "red
flabel [I love logo!]
label [I love logo!]
setlabelheight size
Description: sets the font size for the text to be drawn.
Default value: 14.
Example:
right 90
setlabelheight 40
label "Logo
setlabelfont name
Description: sets the font name for the text to be drawn.
Default value: Arial.
Example:
right 90
setlabelheight 40
setfillcolor "red
label [My turtle]
rt 90 fd 50 lt 90
setlabelfont [Courier New]
label [My turtle]
A procedure (or subroutine) we mean a set composed of declaring and written instructions to a certain processing, assembly created separately and identified by a suggestive name. Thus, you'll be able to teach and test new instructions on your Turtle and to expand the vocabulary that he implicitly knows. For example, wouldn’t it be great to type a command called "rainbow", and Turtle to immediately draw one?

To define a procedure, use the instruction "to" which has the general form:

to procedure_name parameters
instruction_list
end


Let’s consider an example:

to my_rectangle :v1 :v2
  repeat 2 [
    fd :v1
    left 90
    fd :v2
    left 90
  ]
end
my_rectangle 100 50


Try it! As you can see, Turtle learned a new word, "my_rectangle", which is followed by two parameters (v1 and v2). From now on, whenever you call this procedure, Turtle will know what to do...

Note that to define the parameters, we used colon (":") before their names, and in the list of instructions. I also used the statement "repeat" which is useful when you need identical operations to successively come into effect (its form is obvious: "repeat number_of_times [ instruction_list ]").

Of course, we can define a procedure without specifying a parameter:

to my_rectangle
    fd 100
    left 90
    fd 50
    left 90
    fd 100
    left 90
    fd 50
    left 90
end
my_rectangle


To view the list of procedures that you have created over time, click the "My Procedures" button.

Careful. You cannot create procedures that have the name of an existing standard instruction known by Turtle. Also, if you redefine the content of a proceeding one, the old form will be rewritten automatically and will permanently lost its content.
Variables
make name value
Description: assigns the value to the variable named name, which must be a word.
Example:
make "n 23
print :n
make "m "hello
print :m
Random numbers
random numeric_value
Description: outputs a random nonnegative integer less than numeric_value, which must be a positive integer.
Example:
print random 100
Control Structures
repeat n [ instructions_list ]
Description: runs the instructions_list repeatedly, n times.
Example:
repeat 4 [ fd 100 left 90 ]
repcount
Description: outputs the repetition count of the innermost current repeat.
Example:
repeat 10 [ print repcount ]
if condition [ instruction_list1 ]
Description: If condition has the value TRUE, it runs instruction_list1.
Example:
repeat 10 [
  if repcount>5 [
    print repcount
  ]
]
ifelse condition [ instruction_list1 ] [instruction_list2]
Description: If condition has the value TRUE, it runs instruction_list1, else, instruction_list2.
Example:
repeat 10 [
  ifelse repcount<=5
  [ print "lower ]
  [ print "higher ]
]
for [variable lower higher step_optional] [ instruction_list ]
Description: executes instruction_list repeatedly, assigning a new value to the control variable i, within the limits [lower; higher], with the increasing step_optional (if not specified, it is 1 or -1, depending on the interval).
Example 1:
for [i 1 10] [
  print :i
]
Example 2:
for [i 1 10 0.5] [
  print :i
]
while condition [ instruction_list ]
Description: repeatedly evaluates the instruction_list as long as condition remains TRUE.
Evaluates the condition first, so the instruction_list may never be run at all.
Example:
make "n 1
while :n <= 5 [
  print :n
  make "n :n + 1
]
do.while [ instruction_list ] condition
Description: repeatedly evaluates the instruction_list as long as condition remains TRUE.
Evaluates instruction_list first, so is always running at least once.
Example:
make "n 1
do.while [
  print :n
  make "n :n + 1
] :n <= 5
until condition [ instruction_list ]
Description: repeatedly evaluates the instruction_list as long as condition remains TRUE.
Evaluates the condition first, so the instruction_list may never be run at all.
Example:
make "n 1
until :n >= 5 [
  print :n
  make "n :n + 1
]
do.until [ instruction_list ] condition
Description: repeatedly evaluates the instruction_list as long as condition remains TRUE.
Evaluates instruction_list first, so is always running at least once.
Example:
make "n 1
do.until [
  print :n
  make "n :n + 1
] :n >= 5
case expression [ clauses_list ]
Description: if no clause is satisfied, it does nothing.
Example:
make "n 2
show case :n [
  [ [0] "Mother ]
  [ [1] "Father ]
  [ [2] "Child ]
  [ else "Other ]
]
IT&C Essentials, Math, User's Guide!
(free online courses & quizzes)
Online Turtle Graphics - a free and modern web-based logo interpreter
Create an account now! It's EASY and FREE. Learn Logo & Turtle Graphics!
Find us on facebook
Get social with us!
World Map
Check other turtles
around the world!
Need help?
Browse our
support topics
Logo reference
Learn about your
turtle's language