How the Turtle BBCode Works
- To create a turtle, use the guide below to write your code, then wrap it in turtle tags. You might also try copying someone elses code as a starting point.
- "Run Turtle" button: Click this to run the turtle code. Once clicked, the button will become a "Stop" button. Clicking "Stop" will stop the turtle from running, but preserve what had been printed to that point. Now, the button becomes a "Clear" button. Pressing the "Clear" button will clear the turtles output and set the button back to the original "Run Turtle" state.
- "Show/Edit Code" button: Pressing this button will allow you to see the code for this turtle, as well as make TEMPORARY edits to the code. Whatever edits you make here will only be visible to you and will NOT persist. As long as you do not leave/reload the web page OR click the "Clear Edits" button, when you run the turtle it will run with your edits in place. If you want to save your edits, you need to copy the code and either paste it into a new post OR edit your post and replace the existing code inside the turtle tags with the edited code you copied.
- "Clear Edits" button: This button clears any edits you've made to the code locally, essentially reverting it back to the code that is/was posted in the post.
A Leaf (What's a Turtle?)
Reference Guide for Writing Turtle Code
Quick reference logo guide:
Stuff should work in lower or upper case.
WORDS: FW BW ....
NUMBERS: 0, 0.1, 20
LISTS: [1 2 3 5]
SYMBOLS: "foo "bar
VARIABLES: :foo :bar
FUNCTION CALLS: COMMAND arg arg arg ...
(COMMAND arg arg arg ...)
RESET Clear the screen, move home.
FORWARD n Move the turtle forward n pixels
BACKWARD n Move the turtle backward n pixels
RIGHT n Move the turtle left or right n degrees
SETX x Set the co-ordinates of the turtle
SETXY x y
HOME Move the turtle to the home position
CLEARSCREEN Clear the screen
CIRCLE r Draw a Circle of radius r around the turtle
ARC r d Draw an arc of radius r for d degrees
PENUP Lift the pen up and down
COLOR [r g b] Set the pen color
PENWIDTH w Set the pen width
PRINT "foo Prints "foo"
PRINT ["foo "bar] Prints "foo bar"
PR ["foo "bar]
CLEARTEXT Clears previously printed text
1 + 2 1 * 2
SUM 1 2 PRODUCT 1 2
(SUM 1 2 3 ...) (PRODUCT 1 2 3 ...)
1 - 2 1 / 2
DIFFERENCE 1 2 DIVIDE 1 2
1 % 2
MOD 1 2
RANDOM n Return a integer in [0,n)
RERANDOM s Set the random seed value
POWER e m
List Operators (experimental):
These functions may break silently at the moment.
FIRST, HEAD Return the first item in a list
BUTFIRST, TAIL Return the everything but the first item in a list
LAST Return the last item in a list
BUTLAST Return everything but the last item in a list
FPUT item list Return a new list with item at the front
LPUT item list Return a new list with item at the back
ITEM index list Retrieve the indexed item
SETITEM index list value Set the indexed item
EMPTY? list Return true if list is empty
Logical and Comparison:
1 = 1
EQUAL? 1 1
EQUALP 1 1
1 < 2 1 <= 2
LESS? 1 2 LESSEQUAL? 1 2
LESSP 1 2 LESSEQUALP 1 2
2 > 1 2 > 1
GREATER? 2 1 GREATEREQUAL? 2 1
GREATERP 2 1 GREATEREQUALP 2 1
AND TRUE FALSE OR FALSE TRUE
IF COND [IF_TRUE]
IF 2 > 1 [FW 100]
IFELSE COND [IF_TRUE] [IF_FALSE]
IFELSE 2 > 1 [FW 100 RT 90] [BW 100 LT 90]
Setting and getting:
Set x to 1: make "x 1
Adding :n to :x :n + :x
Setting :x to :n + :x make "x :x + :n
REPEAT n [COMMANDS ...]
STOP - Stop the current Repeat or function.
OUTPUT f - Return f.
Defining and Calling:
TO FOO :ARG1 :ARG2 BODY END
TO SQUARE :length
REPEAT 4 [FW :length RT 90]
TO POLYGON :length :sides
REPEAT :sides [FW :length RT 360/:sides]
POLYGON 5 10
Note: Simple Tail recursion is supported.
Related Thread: New Feature Installed - We now have Turtles!
This page has been seen 723 times.
Created byLast updated by