Commands Affecting Turtles (Printable)

alive? [Observer, Turtle]

Returns a boolean. If the turtle is alive, it returns true. If the turtle is not alive it returns false.

alive?-of number [Observer, Turtle]

Returns a boolean. If the turtle with the given who number is alive, it returns true. If the turtle with the given who number is not alive it returns false.

average-of-turtles `[list of commands]` [Observer, Turtle]

Returns the numerical average of the [list of commands] when evaluated accross all the turtles.

bk, back `number` [Turtle]

Turtles move `number` steps backward

breed [Turtle]

Returns the turtle's breed.

breed-at `xcor ycor` [Observer, Turtle]

Reports the breed of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

breed-of `number` [Observer, Turtle]

Reports the breed of the turtle with ID Number `number`.

breed-towards `angle distance` [Observer, Turtle]

Reports the breed of the turtle `distance` away at an angle of `angle`.

cct-and-do, create-custom-turtles-and-do `breed number [list of commands]` [Observer]

Creates `number` turtles of type breed and tells them to do `[list of commands]`.

color [Turtle]

Returns the color of the turtle.

color-at `xcor ycor` [Observer, Turtle]

Reports the color of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller .

color-of `number` [Observer, Turtle]

Reports the color of the turtle with ID Number `number`.

color-towards `angle distance` [Observer, Turtle]

Reports the color of the turtle `distance` away at an angle of `angle`.

count-color `color` [Observer, Turtle]

Returns the number of turtles that are the color `color`.

count-turtles [Observer, Turtle]

Returns the number of turtles.

count-turtles-at `xcor ycor` [Observer, Turtle]

Returns the number of turtles `xcor` units in the x direction and `ycor` units in the y direction away from the caller .

count-turtles-here [Turtle]

Returns the number of turtles sitting on the caller's patch

count-turtles-towards `angle distance` [Observer, Turtle]

Returns the number of turtles `distance` away at angle `angle`.

count-turtles-with `[ilist]` [Observer, Turtle]

Returns the number of turtles whose `ilist` is true.
Sample usage: `show count-turtles-with [(distance 0 0) < 5]`
This gives thenumber of turtles inside a circle of radius 5 centered at the origin.

create-and-do, create-turtles-and do `number ilist` [Observer]

Creates `number` turtles and tells them to do `ilist`.

crt, create-turtles `number` [Observer]

Creates `number` turtles.

ct [Observer]

Clears (kills) all of the turtles.

die [Turtle]

Turtles die, meaning that they stop running all code and disappear forever.

distance `xcor ycor` [Observer, Turtle]

Returns the distance from the caller to (`xcor,ycor`).

distance-nowrap `xcor ycor` [Observer, Turtle]

Returns the distance from the caller to `xcor ycor` without wrapping.

dx [Turtle]

Returns the x-coordinate one step forward from the turtle's current position.

dy [Turtle]

Returns the y-coordinate one step forward from the turtle's current position.

fd, forward `number` [Turtle]

Turtles move `number` steps forward.

grab `ilist` [Observer, Turtle]

Allows the observer or a turtle to instruct another turtle or group of turtles (specified by `turtle_number` or a dlist of `turtle_numbers`) to perform ilist. The ID of the turtle(s) is stored in `partner` if there is one turtle being grabbed, in `partners` if there are many. `grab`s can be nested within each other. If the specified turtle does not exist, the caller skips `ilist` and continues. If you call a procedure within `ilist`, you are still `grab`bing the turtles. A turtle may not `grab` itself. A turtle already being grabbed by one turtle cannot be grabbed by another.

hatch `ilist` [Turtle]

Turtles make exact copy of themselves, tell them to run `ilist`.
Note: Turtles will not run forever buttons while running `ilist`.

heading [Turtle]

Returns the direction that the turtle is facing.

heading-at `xcor ycor` [Observer, Turtle]

Reports the heading of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

heading-of `number` [Observer, Turtle]

Reports the heading of the turtle with ID Number `number`.

heading-towards `angle distance` [Observer, Turtle]

Reports the heading of the turtle `distance` away at an angle of `angle`.

home [Turtle]

Turtles go to coordinates (0,0). This is the same as using setxy 0 0.

ht, hideturtle [Turtle]

Turtles make themselves invisible.

jump `number` [Turtle]

Turtles move `number` steps in the time it takes to make one normal step. For example, jump 15 and fd 1 both take the same amount of time to perform. fd 15, however, would take 15 times as long as jump 15.

kill `number` [Observer, Turtle]

Kills turtle with ID number `number`.

leap `number` [Turtle]

Turtles jump `number` steps only if no other turtle is currently on the patch they will land on.

list-of-turtles [Observer, Turtle]

Returns a list of turtles.

list-of-turtles-at `xcor ycor` [Observer, Turtle]

Returns a list of turtles `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

list-of-turtles-here [Turtle]

Returns a list of turtles on the caller's patch.

list-of-turtles-towards `angle distance` [Observer, Turtle]

Returns a list of turtles at the patch `distance` away at angle `angle`.

list-of-turtles-with condition [Observer, Turtle]

Returns a list of turtles satisfying `condition`.

lt, left `number` [Turtle]

Turtles turn left by `number` degrees.

max-of-turtles-with `pred-ilist ilist`

Reports the highest value of `ilist` when run over the turtles that satisfy `pred-ilist`. If there are no turtles in which `pred-ilist` is true, returns `minnum`, the smallest number possible without going into negative infinity. Note: This command can also be executed by patches, for example within an `ask-patches` statement.

median-of-turtles `[list of commands]` [Observer, Turtle]

Returns the median [list of commands`] when [list of commands]is evaluated for all turtles`.

min-of-turtles-with `pred-ilist ilist`

Reports the lowest value of `ilist` when run over the turtles that satisfy `pred-ilist`. If there are no turtles in which `pred-ilist` is true, returns `maxnum`, the largest number possible without going into positive infinity. Note: This command can also be executed by patches, for example within an `ask-patches` statement.

mode-of-turtles `[list of commands]` [Observer, Turtle]

Returns the mode of the given [list of commands] when run over all the turtles.

myself [Turtle]

During a `count-turtles-with` command, `myself` reports the who number of the turtle which called it.
Example: `count-turtles-with [(distance xcor-of myself ycor-of myself) < 5]` counts all turtles within a radius of 5 units of the caller.

nobody [Observer, Turtle]

An alias for -1

one-of-turtles [Observer, Turtle]

Returns a random turtle.

one-of-turtles-at `xcor ycor` [Observer, Turtle]

Returns a random turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

one-of-turtles-here [Turtle]

Returns a random turtle on the caller's patch other than the caller.

one-of-turtles-towards `angle distance` [Observer, Turtle]

Returns a random turtle at the patch `distance` away at angle `angle`.

one-of-turtles-with `[condition] [list of commands]` [Observer, Turtle]

Chooses a turtle based on the following `[condition]` and runs the commands specified in `[list of commands]`

partner [Observer, Turtle]

Returns the ID number of the turtle being grabbed, or -1 if no turtle is being grabbed.

partners [Observer, Turtle]

Returns a dlist of the turtles being grabbed, or [ ] if no turtles are being grabbed.

pendown? [Turtle]

Returns true if the turtle's pen is down, otherwise false.

pendown?-at `xcor ycor` [Observer, Turtle]

Reports whether the pen of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller is down.

pendown?-of `number` [Observer, Turtle]

Reports whether the pen of the turtle with ID Number `number` is down.

pendown?-towards `angle distance` [Observer, Turtle]

Reports whether the pen of a turtle `distance` away at an angle of `angle` is down.

pu, penup [Turtle]

Turtles pick up their "pens," meaning that they no longer draw when they move.

repeat `number [list of commands]` [Observer, Turtle]

Do `[list of commands]` `number` times.

rt, right `number` [Turtle]

Turtles turn right by `number` degrees.

scale-color `color variable limit1 limit2` [Turtle]

Turtles set their color to a shade of `color` based on their value of `variable`. `limit1` and `limit2` determine the amount of gradation.
Example:
`scale-color blue energy 0 20`
Turtles turn one of twenty shades of blue. Turtles with lower energy turn darker blue.
`scale-color blue energy 20 0`
Turtles turn one of twenty shades of blue. Turtles with lower energy turn lighter blue.

sdev-of-turtles `[list of commands]` [Observer, Turtle]

Returns the standard deviation of the [list of commands] when evaluated accross all the turtles.

setbreed `breedname` [Turtle]

Turtles set their breed to `breedname`.

setbreed-at `xcor ycor breedname` [Observer, Turtle]

Sets the breed of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `breedname`.
See the breeds reference for more information.

setbreed-of `number breedname` [Observer, Turtle]

Sets the breed of the turtle with ID Number `number` to `breedname`.
See the breeds reference for more information.

setbreed-towards `angle distance breedname` [Observer, Turtle]

Sets the breed of the turtle `distance` away in the direction `angle` to `breedname`.
See the breeds reference for more information.

setc, setcolor `colorname (or colornumber)` [Turtle]

Turtles set their color to `colorname (or color number)`.

setc-at `xcor ycor number` [Observer, Turtle]

Sets the color of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `number`.

setc-of `number1 number2` [Observer, Turtle]

Sets the color of the turtle with ID `number1` to color `number2`.

setc-towards `angle distance number` [Observer, Turtle]

Sets the color of the turtle `distance` away if the heading was `angle` to `number`.

seth, setheading `direction` [Turtle]

Turtles set their heading to a `direction` from 0 to 359 degrees.

seth-at `xcor ycor number` [Observer, Turtle]

Sets the heading of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `number`.

seth-of `number1 number2` [Observer, Turtle]

Sets the heading of the turtle with ID `number1` to `number2`.

seth-towards `angle distance number` [Observer, Turtle]

Sets the heading of the turtle `distance` away if the heading was `angle` to `number`.

setpendown?-at `xcor ycor boolean` [Observer, Turtle]

Sets the pendown state of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `boolean`.

setpendown?-of `number boolean` [Observer, Turtle]

Sets the pendown state of the turtle with ID Number `number` to `boolean`.

setpendown?-towards `angle distance boolean` [Observer, Turtle]

Sets the pendown state of a turtle `distance` away at an angle of `angle` to `boolean`.

setshape `shape`-name [Turtle]

Turtles set their shape to `shape-name`.

Note: shape-name can be the number of the shape as well.

setx, setxcor `number` [Turtle]

Turtles set their x-coordinate to `number`.

setxcor-at `xcor ycor number` [Observer, Turtle]

Sets the x-coordinate of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `number`.

setxcor-of `number1 number2` [Observer, Turtle]

Sets the x-coordinate of the turtle with ID `number1` to `number2`.

setxcor-towards `angle distance number` [Observer, Turtle]

Sets the x-coordinate of the turtle `distance` away if the heading was `angle` to `number`.

setxy `number1 number2` [Turtle]

Turtles set their x-coordinate to `number1` and y-coordinate to `number2`.

sety, setycor `number` [Turtle]

Turtles set their y-coordinate to `number`.

setycor-at `xcor ycor number` [Observer, Turtle]

Sets the y-coordinate of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `number`.

setycor-of `number1 number2` [Observer, Turtle]

Sets the y-coordinate of the turtle with ID Number `number1` to `number2`.

setycor-towards `angle distance number` [Observer, Turtle]

Sets the y-coordinate of the turtle `distance` away if the heading was `angle` to `number`.

shown? [Observer, Turtle]

Returns true if the turtle is currently visible, otherwise false.

shown?-at `xcor ycor` [Observer, Turtle]

Reports whether the turtle at (`xcor ycor`) is visible.

shown?-of `number` [Observer, Turtle]

Reports whether the turtle with ID `number` is visible.

shown?-towards `angle distance` [Observer, Turtle]

Reports whether the turtle `distance` away at an angle of `angle` is visible.

sprout `list to run` [Observer, Turtle]

Each patch creates a turtle, which then executes `list to run`.
NOTE: This is a patch command. It must be called from within an `ask-patches` or `ask-patch-at` statement.

st, showturtle [Turtle]

Hidden turtles make themselves visible.

stamp `color` [Observer, Turtle]

Sets color of patch under turtle to `color`

stamp-at `xcor ycor color` [Observer, Turtle]

Sets the color of the patch `xcor` units in the x direction and `ycor` units in the y direction away from the caller to `color`.

stamp-towards `angle distance color` [Turtle]

Sets the color of the patch `distance` away, if the heading were `angle`, to `color`.

step [Turtle]

A synonym for `fd 1`.

sum-of-turtles `ilist` [Observer, Turtle]

Reports the total of evaluating `ilist`in every turtle and adding it up.
Example usage:
`show sum-of-turtles [weight * weight]`
This gives the sum of every turtle's (weight squared).

sum-of-turtles-with `pred-ilist ilist`

Reports the total value of `ilist` when run over the turtles that satisfy `pred-ilist`. If there are no turtles in which `pred-ilist` is true, returns 0. Note: This command can also be executed by patches, for example within an `ask-patches` statement.
Example: `sum-of-turtles-with (color = red) [age]` returns the sum of the ages of all the red turtles.

towards `xcor ycor` [Observer, Turtle]

Returns the angle from the callers xcor and ycor to the specified absolute position specified by `xcor` and`ycor`.

towards-nowrap `xcor ycor` [Observer, Turtle]

Returns the angle from the callers xcor and ycor to the specified absolute position specified by `xcor` and`ycor` without wrapping.

variance-of-turtles `[list of commands]` [Observer, Turtle]

Returns the variance of [list of commands] amongst all the turtles.

who [Turtle]

Returns the ID number of the turtle

who-max-of-frogs `[list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle of breed frogs corresponding to the highest value of [list of commands] along with the highest value of [list of commands].

who-max-of-frogs-with `[condition] [list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle of breed frogs which satifies the [condition] and has the highest value of [list of commands] along with the highest value of [list of commands].

who-max-of-turtles `[list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle corresponding to the highest value of [list of commands] along with the highest value of [list of commands].

who-max-of-turtles-with `[condition] [list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle which satifies the [condition] and has the highest value of [list of commands] along with the highest value of [list of commands].

who-min-of-frogs `[list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle of breed frogs corresponding to the smallest value of [list of commands] along with the smallest value of [list of commands].

who-min-of-frogs-with `[condition] [list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle of breed frogs which satifies the [condition] and has the least value of [list of commands] along with the smallest value of [list of commands].

who-min-of-turtles `[list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtle corresponding to the smallest value of [list of commands] along with the smallest value of [list of commands].

who-min-of-turtles-with `[condition] [list of commands]` [Observer, Turtle]

Returns a list with the who number of the turtlewhich satifies the [condition] and has the least value of [list of commands] along with the smallest value of [list of commands].

xcor [Turtle]

Returns the x-coordinate of the turtle

xcor-at `xcor ycor` [Observer, Turtle]

Reports the x-coordinate of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

xcor-of `number` [Observer, Turtle]

Reports the x-coordinate of the turtle with ID `number`.

xcor-towards `angle distance` [Observer, Turtle]

Reports the x-coordinate of the turtle `distance` away if the heading was `angle`.

ycor [Turtle]

Returns the y-coordinate of the turtle

ycor-at `xcor ycor` [Observer, Turtle]

Reports the y-coordinate of the turtle `xcor` units in the x direction and `ycor` units in the y direction away from the caller.

ycor-of `number` [Observer, Turtle]

Reports the y-coordinate of the turtle with ID `number`.

ycor-towards `angle distance` [Observer, Turtle]

Reports the y-coordinate of the turtle `distance` away if the heading was `angle`.