🐷Catto← Back to home

🐢 The Logo Turtle

The language many of us learned to program with: a turtle with a pen that obeys commands such as forward 100 or right 90. With repetitions and procedures that call themselves you get all the way to fractals. It accepts commands in English and also in Spanish, as in LogoWriter.

Program

The Draw button clears the screen and runs the program. The command center continues from where the turtle was left and knows the procedures in the program.
x 0y 0heading 0°pen down

Worked examples

Ordered from the simplest to the hardest. Each one explains the new idea that appears; the button loads it into the program and draws it. Afterwards, try changing the numbers and see what happens: that is how you learn Logo.

The commands

The screen is 600 steps wide, with the origin at the center. Heading 0 points up and increases clockwise. Commands can be written with or without accents, in lowercase or uppercase, and separated by spaces or on different lines.

CommandShort form or aliasIn SpanishWhat it does
forward 50fdavanza · avWalks 50 steps in the direction it is facing; if the pen is down, it leaves a mark.
back 50bkretrocede · reWalks backward without turning around.
right 90rtgiraderecha · gdTurns 90° clockwise, without moving from its place.
left 90ltgiraizquierda · giTurns the other way, counterclockwise.
penup · pendownpu · pdsubelapiz · bajalapiz (sl · bl)Lifts or lowers the pen: with the pen up it walks without drawing.
penerasegomaWhatever it travels over is erased. Drawing resumes with pendown.
repeat 4 [ … ]repiteRepeats the commands in the brackets. repcount says which pass it is on (1, 2, 3…).
to square :side … endpara … finDefines a new procedure with its inputs (:side). Afterwards it is used like any other command: square 80.
if :n < 5 [ … ]siDoes what is in the brackets only if the condition holds. ifelse cond [ … ] [ … ] chooses between two.
stopaltoEnds the procedure it is in. It is what stops a recursion.
make "side 40hazStores a value in a variable; afterwards it is used as :side.
setpencolor "redsetpcponcolor · ponclPen color: white, red, green, blue, yellow, orange, violet, lightblue, cyan, pink, gray, brown… or a number from 0 to 15. The Spanish color names also work.
setbackground "bluesetbgponfondo · pfBackground color (clears the screen).
setpensize 3grosorWidth of the stroke.
clearscreencsborrapantalla · bpClears everything and takes the turtle to the center, facing up.
homecentroGoes back to the center (drawing, if the pen is down).
setxy 100 50 · setheading 45sethponpos · ponrumbo (pr)Goes to a point, or points to a heading, without going through turns.
hideturtle · showturtleht · stocultatortuga · muestratortuga (ot · mt)Hides or shows the turtle.
print :nshowescribe · esShows a value below the program.
random 10 · sqrt 2 · sin 30 · cos 30—azar · raizcuadrada · sen · cosFunctions: a random integer from 0 to 9, the square root, sine and cosine in degrees.

Calculations are written as in mathematics: :side / 2, :n - 1, 360 / :sides. A minus sign attached to the number and separated from what precedes it, as in dragon :n -1, is a negative number, not a subtraction. Whatever follows a ; is a comment.