This is an approximate grouping. Remember that a turtle-related primitive might still be called by patches or observers, and vice versa. To see which agent (turtles, patches, observer) can actually run each command, consult each individual entry in the dictionary.
back (bk) <breeds>-at <breeds>-here <breeds>-on can-move? clear-turtles (ct) create-<breeds> create-custom-<breeds> create-custom-turtles (cct) create-turtles (crt) die distance distancexy downhill downhill4 dx dy face facexy forward (fd) hatch hatch-<breeds> hide-turtle (ht) home inspect is-<breed>? is-turtle? jump left (lt) myself nobody -of other-turtles-here other-<breeds>-here patch-ahead patch-at-heading-and-distance patch-here patch-left-and-ahead patch-right-and-ahead pen-down (pd) pen-erase (pe) pen-up (pu) random-xcor random-ycor right (rt) self set-default-shape __set-line-thickness setxy shapes show-turtle (st) sprout sprout-<breeds> stamp stamp-erase subject subtract-headings __tie towards towardsxy turtle turtles turtles-at turtles-from turtles-here turtles-on turtles-own __untie uphill value-from
clear-patches (cp) diffuse diffuse4 distance distancexy import-pcolors inspect is-patch? myself neighbors neighbors4 nobody nsum nsum4 -of patch patch-at patch-ahead patch-at-heading-and-distance patch-here patch-left-and-ahead patch-right-and-ahead patches patches-from patches-own random-pxcor random-pycor self sprout sprout-<breeds> subject value-from
any? ask at-points <breeds>-at <breeds>-here <breeds>-on count histogram-from in-cone in-radius is-agent? is-agentset? is-patch-agentset? is-turtle-agentset? max-one-of min-one-of n-of neighbors neighbors4 one-of other-turtles-here other-<breeds>-here patches patches-from sort sort-by turtles with with-max with-min turtles-at turtles-from turtles-here turtles-on values-from
color extract-hsb extract-rgb hsb import-pcolors pcolor rgb scale-color shade-of? wrap-color
and carefully end error-message foreach if ifelse ifelse-value let loop map not or repeat report run runresult ; (semicolon) set stop startup to to-report wait while without-interruption xor
clear-all (ca) clear-drawing (cd) clear-patches (cp) clear-turtles (ct) display import-drawing import-pcolors no-display max-pxcor max-pycor min-pxcor min-pycor world-width world-height
follow follow-me reset-perspective (rp) ride ride-me subject watch watch-me
hubnet-broadcast hubnet-broadcast-view hubnet-enter-message? hubnet-exit-message? hubnet-fetch-message hubnet-message hubnet-message-source hubnet-message-tag hubnet-message-waiting? hubnet-reset hubnet-send hubnet-send-view hubnet-set-client-interface
beep clear-output date-and-time export-view export-interface export-output export-plot export-all-plots export-world import-drawing import-pcolors import-world mouse-down? mouse-inside? mouse-xcor mouse-ycor output-print output-show output-type output-write print read-from-string reset-timer set-current-directory show timer type user-directory user-file user-new-file user-input user-message user-one-of user-yes-or-no? write
file-at-end? file-close file-close-all file-delete file-exists? file-open file-print file-read file-read-characters file-read-line file-show file-type file-write user-directory user-file user-new-file
but-first but-last empty? filter first foreach fput is-list? item last length list lput map member? modes n-of n-values position one-of reduce remove remove-duplicates remove-item replace-item reverse sentence shuffle sort sort-by sublist values-from
Operators (+, <, >, =, !=, <=, >=) but-first but-last empty? first is-string? item last length member? position remove remove-item read-from-string replace-item reverse substring word
Arithmetic Operators (+, *, -, /, ^, <, >, =, !=, <=, >=) abs acos asin atan ceiling cos e exp floor int ln log max mean median min mod modes new-seed pi precision random random-exponential random-float random-gamma random-int-or-float random-normal random-poisson random-seed remainder round sin sqrt standard-deviation subtract-headings sum tan variance
autoplot? auto-plot-off auto-plot-on clear-all-plots clear-plot create-temporary-plot-pen export-plot export-all-plots histogram-from histogram-list plot plot-name plot-pen-down (ppd) plot-pen-reset plot-pen-up (ppu) plot-x-max plot-x-min plot-y-max plot-y-min plotxy ppd ppu set-current-plot set-current-plot-pen set-histogram-num-bars set-plot-pen-color set-plot-pen-interval set-plot-pen-mode set-plot-x-range set-plot-y-range
__both-ends __create-<breed>-from __create-<breeds>-from __create-<breed>-to __create-<breeds>-to __create-<breed>-with __create-<breeds>-with __end1 __end2 __in-<breed>-neighbor? __in-<breed>-neighbors __in-<breed>-from __is-link? __layout-circle __layout-magspring __layout-radial __layout-spring __layout-tutte __<breed>-neighbor? __<breed>-neighbors __<breed>-with __my-<breeds> __my-in-<breeds> __my-out-<breeds> __other-end __out-<breed>-neighbor? __out-<breed>-neighbors __out-<breed>-to __remove-<breed>-from __remove-<breeds>-from __remove-<breed>-to __remove-<breeds>-to __remove-<breed>-with __remove-<breeds>-with
movie-cancel movie-close movie-grab-view movie-grab-interface movie-set-frame-rate movie-start movie-status
breed color heading hidden? label label-color pen-mode pen-size shape size who xcor ycor
pcolor plabel plabel-color pxcor pycor
breed end globals patches-own to to-report turtles-own
e = 2.718281828459045
pi = 3.141592653589793
false
true
black = 0.0
gray = 5.0
white = 9.9
red = 15.0
orange = 25.0
brown = 35.0
yellow = 45.0
green = 55.0
lime = 65.0
turquoise = 75.0
cyan = 85.0
sky = 95.0
blue = 105.0
violet = 115.0
magenta = 125.0
pink = 135.0
See the Colors section of the Programming Guide for more details.
Reports the absolute value of number.
show abs -7 => 7 show abs 5 => 5
Reports the arc cosine (inverse cosine) of the given number. The input must be in the range -1.0 to 1.0. The result is in degrees, and lies in the range 0.0 to 180.0.
Reports true if both condition1 and condition2 are true.
Note that if condition1 is false, then condition2 will not be run (since it can't affect the result).
if (pxcor > 0) and (pycor > 0)
[ set pcolor blue ] ;; the upper-right quadrant of
;; patches turn blue
Reports true if the given agentset is non-empty, false otherwise.
Equivalent to "count agentset > 0", but arguably more readable.
if any? turtles with [color = red] [ show "at least one turtle is red!" ]
Note: "nobody" is not an agentset. You only get nobody back in situations where you were expecting a single agent, not a whole agentset. If any? gets nobody as input, an error results.
See also nobody.
All of these operators take two inputs, and all act as "infix operators" (going between the two inputs, as in standard mathematical use). NetLogo correctly supports order of operations for infix operators.
The operators work as follows: + is addition, * is multiplication, - is subtraction, / is division, ^ is exponentiation, < is less than, > is greater than, = is equal to, != is not equal to, <= is less than or equal, >= is greater than or equal.
Note that the subtraction operator (-) always takes two inputs unless you put parentheses around it, in which case it can take one input. For example, to take the negative of x, write (- x), with the parentheses.
All of the comparison operators also work on strings, and the addition operator (+) also functions as a string concatenation operator (see example below).
If you are not sure how NetLogo will interpret your code, you should insert parentheses.
show 5 * 6 + 6 / 3 => 32 show 5 * (6 + 6) / 3 => 20 show "tur" + "tle" => "turtle"
Reports the arc sine (inverse sine) of the given number. The input must be in the range -1.0 to 1.0. The result is in degrees, and lies in the range -90.0 to 90.0.
The specified agent or agentset runs the given commands.
ask turtles [ fd 1 ] ;; all turtles move forward one step ask patches [ set pcolor red ] ;; all patches turn red ask turtle 4 [ rt 90 ] ;; only the turtle with id 4 turns right
Note: only the observer can ask all turtles or all patches. This prevents you from inadvertently having all turtles ask all turtles or all patches ask all patches, which is a common mistake to make if you're not careful about which agents will run the code you are writing.
Note: Only the agents that are in the agentset at the time the ask begins run the commands.
Reports a subset of the given agentset that includes only the agents on the patches the given distances away from the calling agent. The distances are specified as a list of two-item lists, where the two items are the x and y offsets.
If the caller is the observer, then the points are measured relative to the origin, in other words, the points are taken as absolute patch coordinates.
If the caller is a turtle, the points are measured relative to the turtle's exact location, and not from the center of the patch under the turtle.
ask turtles at-points [[2 4] [1 2] [10 15]]
[ fd 1 ] ;; only the turtles on the patches at the
;; distances (2,4), (1,2) and (10,15),
;; relative to the caller, move
Reports the arc tangent, in degrees (from 0 to 360), of x divided by y.
When y is 0: if x is positive, it reports 90; if x is negative, it reports 270; if x is zero, you get an error.
Note that this version of atan is designed to conform to the geometry of the NetLogo world, where a heading of 0 is straight up, 90 is to the right, and so on clockwise around the circle. (Normally in geometry an angle of 0 is right, 90 is up, and so on, counterclockwise around the circle, and atan would be defined accordingly.)
show atan 1 -1 => 135.0 show atan -1 1 => 315.0
Reports true if auto-plotting is on for the current plot, false otherwise.
This pair of commands is used to control the NetLogo feature of auto-plotting in the current plot. Auto-plotting will automatically update the x and y axes of the plot whenever the current pen exceeds these boundaries. It is useful when wanting to display all plotted values in the current plot, regardless of the current plot ranges.

The turtle moves backward by number steps. (If number is negative, the turtle moves forward.)
Turtles using this primitive can move a maximum of one unit per time increment. So bk 0.5 and bk 1 both take one unit of time, but bk 3 takes three.
If the turtle cannot move backward number steps because it is not permitted by the current topology the turtle will complete as many steps of 1 as it can and stop.
See also forward, jump, can-move?.
Emits a beep. Note that the beep is emitted immediately, so several beep commands in succession will only produce a single audible sound.
Example:
beep ;; emits one beep
repeat 3 [ beep ] ;; emits 3 beeps at the exact same time,
;; so you only hear one sound
repeat 3 [ beep wait 0.1 ] ;; produces 3 beeps in succession,
;; separated by 1/10th of a second

Reports the agentset of the 2 nodes connected by this link turtle.
;; Let a directed link turtle L be connected from N1 to N2. ask L [ show __both-ends ;; displays an agentset consisting of N1 and N2. ]
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

This is a built-in turtle variable. It holds the agentset of all turtles of the same breed as this turtle. (For turtles that do not have any particular breed, this is the turtles agentset of all turtles.) You can set this variable to change a turtle's breed.
See also breed.
Example:
breed [cats cat] breed [dogs dog] ;; turtle code: if breed = cats [ show "meow!" ] set breed dogs show "woof!"
This keyword, like the globals, turtles-own, and patches-own keywords, can only be used at the beginning of the Procedures tab, before any procedure definitions. It defines a breed. The first input defines the name of the agentset associated with the breed. The second input defines the name of a single member of the breed.
Any turtle of the given breed:
Most often, the agentset is used in conjunction with ask to give commands to only the turtles of a particular breed.
breed [mice mouse] breed [frogs frog] to setup ca create-mice 50 ask mice [ set color white ] create-frogs 50 ask frogs [ set color green ] show breed-of one-of mice ;; prints mice show breed-of one-of frogs ;; prints frogs end show mouse 1 ;; prints (mouse 1) show frog 51 ;; prints (frog 51) show turtle 51 ;; prints (frog 51)
See also globals, patches-own, turtles-own, <breeds>-own, create-<breeds>, create-custom-<breeds>, <breeds>-at, <breeds>-here.
When used on a list, but-first reports all of the list items of list except the first, and but-last reports all of the list items of list except the last.
On strings, but-first and but-last report a shorter string omitting the first or last character of the original string.
;; mylist is [2 4 6 5 8 12] set mylist but-first mylist ;; mylist is now [4 6 5 8 12] set mylist but-last mylist ;; mylist is now [4 6 8] show but-first "string" ;; prints "tring" show but-last "string" ;; prints "strin"

Reports true if the calling turtle can move distance in the direction it is facing without violating the topology; reports false otherwise.
It is equivalent to:
patch-ahead distance != nobody
Runs commands1. If a runtime error occurs inside commands1, NetLogo won't stop and alert the user that an error occurred. It will suppress the error and run commands2 instead.
The error-message reporter can be used in commands2 to find out what error was suppressed in commands1. See error-message.
Note: both sets of commands run without interruption (as with the without-interruption command).
carefully [ show 1 / 1 ] [ print error-message ] => 1 carefully [ show 1 / 0 ] [ print error-message ] => division by zero
Reports the smallest integer greater than or equal to number.
show ceiling 4.5 => 5 show ceiling -4.5 => -4

Resets all global variables to zero, and calls clear-turtles, clear-patches, clear-drawing, clear-all-plots, and clear-output.

Clears every plot in the model. See clear-plot for more information.

Clears all lines and stamps drawn by turtles.

Clears all text from the model's output area, if it has one. Otherwise does nothing.

Clears the patches by resetting all patch variables to their default initial values, including setting their color to black.
In the current plot only, resets all plot pens, deletes all temporary plot pens, resets the plot to its default values (for x range, y range, etc.), and resets all permanent plot pens to their default values. The default values for the plot and for the permanent plot pens are set in the plot Edit dialog, which is displayed when you edit the plot. If there are no plot pens after deleting all temporary pens, that is to say if there are no permanent plot pens, a default plot pen will be created with the following initial settings:
See also clear-all-plots.

Kills all turtles.
See also die.

This is a built-in turtle variable. It holds the color of the turtle. You can set this variable to make the turtle change color.
See also pcolor.
Reports the cosine of the given angle. Assumes the angle is given in degrees.
show cos 180 => -1.0
Reports the number of agents in the given agentset.
show count turtles ;; prints the total number of turtles show count patches with [pcolor = red] ;; prints the total number of red patches
Used for creating link turtles between agents. Links are special turtles. A link turtle's size is always equal to the distance between the two node turtles it links together. Its heading is always equal to the heading from one node turtle to the other. Its location is always halfway between the two node turtles. Their default shape is "link".
__create-<breed>-with creates an undirected link between the caller and agent. __create-<breed>-to creates a link from the caller to agent. __create-<breed>-from creates a link from agent to the caller.
When the plural form of the breed name is used, an agentset is expected instead of an agent and links are created between the caller and all agents in the agentset.
The command block is the set of commands each newly formed link runs. (The links are created all at once then run one at a time, in random order.)
A node cannot be linked to itself. Also, you cannot have more than one undirected link of the same breed between the same two nodes, nor can you have more than one directed link of the same breed going in the same direction between two nodes.
breed [links link] ;; breed for network links
to make-friend [ frd ] ;; node procedure
;; creates a friendship link between
;; the node on which this
;; procedure was called and the node "frd".
__create-link-to frd
[
set color blue
]
end
to become-friendly ;; node procedure
;; makes this node link with an agentset of turtles
__create-links-to friends
[]
end
This command is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

Creates number new turtles . New turtles start at position (0, 0), are created with the 14 primary colors, and have headings from 0 to 360, evenly spaced.
crt 100 ask turtles [ fd 10 ] ;; makes an evenly spaced circle
If the create-<breeds> form is used, the new turtles are created as members of the given breed.

Creates number new turtles (of the given breed, if specified). New turtles start at position (0, 0). New turtles are created with the 14 primary colors and have headings from 0 to 360, evenly spaced.
The new turtles immediately run commands. This is useful for giving the new turtles a different color, heading, or whatever. (The new turtles are created all at once then run one at a time, in random order.)
breed [canaries canary]
breed [snakes snake]
to setup
ca
create-custom-canaries 50
[ set color yellow ]
create-custom-snakes 50
[ set color green ]
end
Note: While the commands are running, no other agents are allowed to run any code (as with the without-interruption command). This ensures that the new turtles cannot interact with any other agents until they are fully initialized. In addition, no display updates take place until the commands are done. This ensures that the new turtles are never drawn in the view until they are fully initialized.
A new temporary plot pen with the given name is created in the current plot and set to be the current pen.
Few models will want to use this primitive, because all temporary pens disappear when clear-plot or clear-all-plots are called. The normal way to make a pen is to make a permanent pen in the plot's Edit dialog.
If a temporary pen with that name already exists in the current plot, no new pen is created, and the existing pen is set to the the current pen. If a permanent pen with that name already exists in the current plot, you get a runtime error.
The new temporary plot pen has the following initial settings:
See: clear-plot, clear-all-plots, and set-current-plot-pen.
Reports a string containing the current date and time. The format is shown below. All fields are fixed width, so they are always at the same locations in the string. The potential resolution of the clock is milliseconds. (Whether you get resolution that high in practice may vary from system to system, depending on the capabilities of the underlying Java Virtual Machine.)
show date-and-time => "01:19:36.685 PM 19-Sep-2002"

The turtle dies.
if xcor > 20 [ die ]
;; all turtles with xcor greater than 20 die
See also: ct

Tells each patch to share (number * 100) percent of the value of patch-variable with its eight neighboring patches. number should be between 0 and 1. Regardless of topology the sum of patch-variable will be conserved across the world. If a patch has fewer than eight neighbors the remainder stays on the patch at the edge of the world.
Note that this is an observer command only, even though you might expect it to be a patch command. (The reason is that it acts on all the patches at once -- patch commands act on individual patches.)
diffuse chemical 0.5 ;; each patch diffuses 50% of its variable ;; chemical to its neighboring 8 patches. Thus, ;; each patch gets 1/8 of 50% of the chemical ;; from each neighboring patch.)

Like diffuse, but only diffuses to the four neighboring patches (to the north, south, east, and west), not to the diagonal neighbors.
diffuse4 chemical 0.5 ;; each patch diffuses 50% of its variable ;; chemical to its neighboring 4 patches. Thus, ;; each patch gets 1/4 of 50% of the chemical ;; from each neighboring patch.)
Causes the current view to be updated immediately.
Also undoes the effect of the no-display command, so that if display updates were suspended by that command, they will resume.
no-display ask turtles [ jump 10 set color blue set size 5 ] display ;; turtles move, change color, and grow, with none of ;; their intermediate states visible to the user, only ;; their final state
Even if no-display was not used, "display" can still be useful, because ordinarily NetLogo is free to skip some view updates, so that fewer total updates take place, so that models run faster. This command lets you force a view update, so whatever changes have taken place in the world are visible to the user.
ask turtles [ set color red ] display ask turtles [ set color blue] ;; turtles turn red, then blue; use of "display" forces ;; red turtles to appear briefly
There is exception to the "immediately" rule: if the command is used by an agent that is running "without interruption" (such as via the without-interruption command, inside a procedure defined using to-report, or inside a command such as hatch, sprout, or cct), then the view update takes place once the agent is done running without interruption.
Note that display and no-display operate independently of the switch in the view control strip that freezes the view.
See also no-display.

Reports the distance from this agent to the given turtle or patch.
The distance to or a from a patch is measured from the center of the patch. Turtles and patches use the wrapped distance (around the edges of the view) if wrapping is allowed by the topology and the wrapped distance is shorter than the on-screen distance.

Reports the distance from this agent to the point (xcor, ycor).
The distance from a patch is measured from the center of the patch. Turtles and patches use the wrapped distance (around the edges of the view) if wrapping is allowed by the topology and the wrapped distance is shorter than the on-screen distance.
if (distancexy 0 0) > 10 [ set color green ] ;; all turtles more than 10 units from ;; the center of the screen turn green.

Reports the turtle heading (between 0 and 359 degrees) in the direction of the minimum value of the variable patch-variable, of the patches in a one-patch radius of the turtle. (This could be as many as eight patches or as few as one patch, depending on the position of the turtle within its patch and the topology of the world.)
If there are multiple patches that have the same smallest value, a random one of those patches will be selected.
If the patch is located directly to the north, south, east, or west of the patch that the turtle is currently on, a multiple of 90 degrees is reported. However, if the patch is located to the northeast, northwest, southeast, or southwest of the patch that the turtle is currently on, the direction the turtle would need to reach the nearest corner of that patch is reported.
See also downhill4, uphill, uphill4.

Reports the turtle heading (between 0 and 359 degrees) as a multiple of 90 degrees in the direction of the minimum value of the variable patch-variable, of the four patches to the north, south, east, and west of the turtle. If there are multiple patches that have the same least value, a random patch from those patches will be selected.
See also downhill, uphill, uphill4.

Reports the x-increment or y-increment (the amount by which the turtle's xcor or ycor would change) if the turtle were to take one step forward in its current heading.
Note: dx is simply the sine of the turtle's heading, and dy is simply the cosine. (If this is the reverse of what you expected, it's because in NetLogo a heading of 0 is north and 90 is east, which is the reverse of how angles are usually defined in geometry.)
Note: In earlier versions of NetLogo, these primitives were used in many situations where the new patch-ahead primitive is now more appropriate.
Reports true if the given list or string is empty, false otherwise.
Note: the empty list is written []. The empty string is written "".
Used to conclude a procedure. See to and to-report.

Reports the first end of a link. In a directed link, the direction of the link is from end1 to the end2.
;; Let a directed link L be connected from N1 to N2. ask L [ show __end1 ;; prints N1 ]
Even though in an undirected link order of nodes is not important, end1 is deterministic and reports the same node on repeated calls by an undirected link.
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

Reports the second end of a link. In a directed link, the direction of the link is from end1 to the end2.
;; Let a directed link L be connected from N1 to N2. ask L [ show __end2 ;; prints N2 ]
Even though in an undirected link order of nodes is not important, end2 is deterministic and reports the same node from repeated calls by an undirected link.
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports a string describing the error that was suppressed by carefully.
This reporter can only be used in the second block of a carefully command.
See also carefully.
Runs the given commands at most every number seconds.
By itself, every doesn't make commands run over and over again. You need to use every inside a loop, or inside a forever button, if you want the commands run over and over again. every only limits how often the commands run.
More technically, its exact behavior is as follows. When an agent reaches an "every", it checks a timer to see if the given amount of time has passed since the last time the same agent ran the commands in the "every" in the same context. If so, it runs the commands; otherwise they are skipped and execution continues.
Here, "in the same context" means during the same ask (or button press or command typed in the Command Center). So it doesn't make sense to write ask turtles [ every 0.5 [ ... ] ], because when the ask finishes the turtles will all discard their timers for the "every". The correct usage is shown below.
every 0.5 [ ask turtles [ fd 1 ] ] ;; twice a second the turtles will move forward 1 every 2 [ set index index + 1 ] ;; every 2 seconds index is incremented
See also wait.
Reports the value of e raised to the number power.
Note: This is the same as e ^ number.
export-view writes the current contents of the current view to an external file given by the string filename. The file is saved in PNG (Portable Network Graphics) format, so it is recommended to supply a filename ending in ".png".
export-interface is similar, but for the whole interface tab.
export-output writes the contents of the model's output area to an external file given by the string filename. (If the model does not have a separate output area, the output portion of the Command Center is used.)
export-plot writes the x and y values of all points plotted by all the plot pens in the plot given by the string plotname to an external file given by the string filename. If a pen is in bar mode (mode 0) and the y value of the point plotted is greater than 0, the upper-left corner point of the bar will be exported. If the y value is less than 0, then the lower-left corner point of the bar will be exported.
export-all-plots writes every plot in the current model to an external file given by the string filename. Each plot is identical in format to the output of export-plot.
export-world writes the values of all variables, both built-in and user-defined, including all observer, turtle, and patch variables, the drawing, and the contents of the output area if one exists, to an external file given by the string filename. (The result file can be read back into NetLogo with the import-world primitive.)
export-plot, export-all-plots and export-world save files in in plain-text, "comma-separated values" (.csv) format. CSV files can be read by most popular spreadsheet and database programs as well as any text editor.
If the file already exists, it is overwritten.
If you wish to export to a file in a location other than the model's location, you should include the full path to the file you wish to export. (Use the forward-slash "/" as the folder separator.)
Note that the functionality of these primitives is also available directly from NetLogo's File menu.
export-world "fire.csv" ;; exports the state of the model to the file fire.csv ;; located in the NetLogo folder export-plot "Temperature" "c:/My Documents/plot.csv" ;; exports the plot named ;; "Temperature" to the file plot.csv located in ;; the C:\My Documents folder export-all-plots "c:/My Documents/plots.csv" ;; exports all plots to the file plots.csv ;; located in the C:\My Documents folder
Reports a list of three values in the range 0.0 to 1.0 representing the hue, saturation and brightness, respectively, of the given NetLogo color in the range 0 to 140.
show extract-hsb red => [0.0090 0.809 0.843] show extract-hsb cyan => [0.5 0.571 0.769]
See also hsb, rgb, extract-rgb.
Reports a list of three values in the range 0.0 to 1.0 representing the levels of red, green, and blue, respectively, of the given NetLogo color in the range 0 to 140.
show extract-rgb red => [0.843 0.196 0.161] show extract-rgb cyan => [0.329 0.769 0.769]
See also rgb, hsb, extract-hsb.

Set the caller's heading towards agent.
If wrapping is allowed by the topology and the wrapped distance (around the edges of the view) is shorter than the on-screen distance, face will use the heading of the wrapped path.
If the caller and the agent are at the exact same position, the caller's heading won't change.

Set the caller's heading towards the point (x,y).
If wrapping is allowed by the topology and the wrapped distance (around the edges of the view) is shorter than the on-screen distance and wrapping is allowed, facexy will use the heading of the wrapped path.
If the caller is on the point (x,y), the caller's heading won't change.
Reports true when there are no more characters left to read in from the current file (that was opened previously with file-open). Otherwise, reports false.
file-open "myfile.txt" print file-at-end? => false ;; Can still read in more characters print file-read-line => This is the last line in file print file-at-end => true ;; We reached the end of the file
See also file-open, file-close-all.
Closes a file that has been opened previously with file-open.
Note that this and file-close-all are the only ways to restart to the beginning of an opened file or to switch between file modes.
If no file is open, does nothing.
See also file-close-all, file-open.
Closes all files (if any) that have been opened previously with file-open.
See also file-close, file-open.
Deletes the file specified as string
string must be an existing file with writable permission by the user. Also, the file cannot be open. Use the command file-close to close an opened file before deletion.
Note that the string can either be a file name or an absolute file path. If it is a file name, it looks in whatever the current directory is. This can be changed using the command set-current-directory. It is defaulted to the model's directory.
Reports true if string is the name of an existing file on the system. Otherwise it reports false.
Note that the string can either be a file name or an absolute file path. If it is a file name, it looks in whatever the current directory is. This can be changed using the command set-current-directory. It defaults to to the model's directory.
This command will interpret string as a path name to a file and open the file. You may then use the reporters file-read, file-read-line, and file-read-characters to read in from the file, or file-write, file-print, file-type, or file-show to write out to the file.
Note that you can only open a file for reading or writing but not both. The next file i/o primitive you use after this command dictates which mode the file is opened in. To switch modes, you need to close the file using file-close.
Also, the file must already exist if opening a file in reading mode.
When opening a file in writing mode, all new data will be appended to the end of the original file. If there is no original file, a new blank file will be created in its place. (You must have write permission in the file's directory.) (If you don't want to append, but want to replace the file's existing contents, use file-delete to delete it first, perhaps inside a carefully if you're not sure whether it already exists.)
Note that the string can either be a file name or an absolute file path. If it is a file name, it looks in whatever the current directory is. This can be changed using the command set-current-directory. It is defaulted to the model's directory.
file-open "myfile-in.txt" print file-read-line => First line in file ;; File is in reading mode file-open "C:\\NetLogo\\myfile-out.txt" ;; assuming Windows machine file-print "Hello World" ;; File is in writing mode
See also file-close.
Prints value to an opened file, followed by a carriage return.
The calling agent is not printed before the value, unlike file-show.
Note that this command is the file i/o equivalent of print, and file-open needs to be called before this command can be used.
See also file-show, file-type, and file-write.
This reporter will read in the next constant from the opened file and interpret it as if it had been typed in the Command Center. It reports the resulting value. The result may be a number, list, string, boolean, or the special value nobody.
Whitespace separates the constants. Each call to file-read will skip past both leading and trailing whitespace.
Note that strings need to have quotes around them. Use the command file-write to have quotes included.
Also note that the file-open command must be called before this reporter can be used, and there must be data remaining in the file. Use the reporter file-at-end? to determine if you are at the end of the file.
file-open "myfile.data" print file-read + 5 ;; Next value is the number 1 => 6 print length file-read ;; Next value is the list [1 2 3 4] => 4
See also file-open and file-write.
Reports the given number of characters from an opened file as a string. If there are fewer than that many characters left, it will report all of the remaining characters.
Note that it will return every character including newlines and spaces.
Also note that the file-open command must be called before this reporter can be used, and there must be data remaining in the file. Use the reporter file-at-end? to determine if you are at the end of the file.
file-open "myfile.txt" print file-read-characters 8 ;; Current line in file is "Hello World" => Hello Wo
See also file-open.
Reads the next line in the file and reports it as a string. It determines the end of the file by a carriage return, an end of file character or both in a row. It does not return the line terminator characters.
Also note that the file-open command must be called before this reporter can be used, and there must be data remaining in the file. Use the reporter file-at-end? to determine if you are at the end of the file.
file-open "myfile.txt" print file-read-line => Hello World
See also file-open.
Prints value to an opened file, preceded by the calling agent, and followed by a carriage return. (The calling agent is included to help you keep track of what agents are producing which lines of output.) Also, all strings have their quotes included similar to file-write.
Note that this command is the file i/o equivalent of show, and file-open needs to be called before this command can be used.
See also file-print, file-type, and file-write.
Prints value to an opened file, not followed by a carriage return (unlike file-print and file-show). The lack of a carriage return allows you to print several values on the same line.
The calling agent is not printed before the value. unlike file-show.
Note that this command is the file i/o equivalent of type, and file-open needs to be called before this command can be used.
See also file-print, file-show, and file-write.
This command will output value, which can be a number, string, list, boolean, or nobody to an opened file not followed by a carriage return (unlike file-print and file-show).
The calling agent is not printed before the value, unlike file-show. Its output also includes quotes around strings and is prepended with a space. It will output the value in such a manner that file-read will be able to interpret it.
Note that this command is the file i/o equivalent of write, and file-open needs to be called before this command can be used.
file-open "locations.txt" ask turtles [ file-write xcor file-write ycor ]
See also file-print, file-show, and file-type.
Reports a list containing only those items of list for which the boolean reporter is true -- in other words, the items satisfying the given condition.
In reporter, use ? to refer to the current item of list.
show filter [? < 3] [1 3 2] => [1 2] show filter [first ? != "t"] ["hi" "there" "everyone"] => ["hi" "everyone"]
On a list, reports the first (0th) item in the list.
On a string, reports a one-character string containing only the first character of the original string.
Reports the largest integer less than or equal to number.
show floor 4.5 => 4 show floor -4.5 => -5

Similar to ride, but, in the 3D view, the view is behind and above turtle.
See also follow-me, ride, reset-perspective, watch, subject.

Asks the observer to follow the calling turtle.
See also follow.
With a single list, runs commands for each item of list. In commands, use ? to refer to the current item of list.
foreach [1.1 2.2 2.6] [ show ? + " -> " + round ? ] => 1.1 -> 1 => 2.2 -> 2 => 2.6 -> 3
With multiple lists, runs commands for each group of items from each list. So, they are run once for the first items, once for the second items, and so on. All the lists must be the same length. In commands, use ?1 through ?n to refer to the current item of each list.
Some examples make this clearer:
(foreach [1 2 3] [2 4 6] [ show "the sum is: " + (?1 + ?2) ]) => "the sum is: 3" => "the sum is: 6" => "the sum is: 9" (foreach list (turtle 1) (turtle 2) [3 4] [ ask ?1 [ fd ?2 ] ]) ;; turtle 1 moves forward 3 patches ;; turtle 2 moves forward 4 patches

The turtle moves forward by number steps. (If number is negative, the turtle moves backward.)
Turtles using this primitive can move a maximum of one unit per turn. So fd 0.5 and fd 1 both take one turn, but fd 3 takes three.
If the turtle cannot move forward number steps because it is not permitted by the current topology the turtle will complete as many steps of 1 as it can, then stop.
Adds item to the beginning of a list and reports the new list.
;; suppose mylist is [5 7 10] set mylist fput 2 mylist ;; mylist is now [2 5 7 10]
This keyword, like the breed, <breeds>-own, patches-own, and turtles-own keywords, can only be used at the beginning of a program, before any function definitions. It defines new global variables. Global variables are "global" because they are accessible by all agents and can be used anywhere in a model.
Most often, globals is used to define variables or constants that need to be used in many parts of the program.

This turtle creates number new turtles, each identical to its parent, and asks the new turtles to run commands. You can use the commands to give the new turtles different colors, headings, or whatever. (The new turtles are created all at once, then run one at a time, in random order.)
If the hatch-<breeds> form is used, the new turtles are created as members of the given breed. Otherwise, the new turtles are the same breed as their parent.
Note: While the commands are running, no other agents are allowed to run any code (as with the without-interruption command). This ensures that the new turtles cannot interact with any other agents until they are fully initialized. In addition, no display updates take place until the commands are done. This ensures that the new turtles are never drawn in an partly initialized state.
hatch 1 [ lt 45 fd 1 ] ;; this turtle creates one new turtle, ;; and the child turns and moves away hatch-sheep 1 [ set color black ] ;; this turtle creates a new turtle ;; of the sheep breed

This is a built-in turtle variable. It indicates the direction the turtle is facing. This is a number greater than or equal to 0 and less than 360. 0 is north, 90 is east, and so on. You can set this variable to make a turtle turn.
Example:
set heading 45 ;; turtle is now facing northeast set heading heading + 10 ;; same effect as "rt 10"

This is a built-in turtle variable. It holds a boolean (true or false) value indicating whether the turtle is currently hidden (i.e., invisible). You can set this variable to make a turtle disappear or reappear.
See also hide-turtle, show-turtle.
Example:
set hidden? not hidden? ;; if turtle was showing, it hides, and if it was hiding, ;; it reappears

The turtle makes itself invisible.
Note: This command is equivalent to setting the turtle variable "hidden?" to true.
See also show-turtle.
Draws a histogram showing the frequency distribution of the values reported when all agents in the agentset run the given reporter. The heights of the bars in the histogram represent the numbers of agents with values in those ranges.
Before the histogram is drawn, first any previous points drawn by the current plot pen are removed.
The reporter should report a numeric value. Any non-numeric values reported are ignored.
The histogram is drawn on the current plot using the current plot pen and pen color. Use set-plot-x-range to control the range of values to be histogrammed, and set the pen interval (either directly with set-plot-pen-interval, or indirectly via set-histogram-num-bars) to control how many bars that range is split up into.
Be sure that if you want the histogram drawn with bars that the current pen is in bar mode (mode 1).
As of NetLogo 2.0.2, for histogramming purposes the plot's X range is not considered to include the maximum X value. Values equal to the maximum X will fall outside of the histogram's range.
histogram-from turtles [color] ;; draws a histogram showing how many turtles there are ;; of each color
Note: using this primitive amounts to the same thing as writing: histogram-list values-from agentset [ reporter ], but is more efficient.
Histograms the values in the given list, after first removing any previous points drawn by the current plot pen.
See histogram-from, above, for more information.

The calling turtles moves to the origin (0,0). Equivalent to setxy 0 0.
Reports a number in the range 0 to 140, not including 140 itself, that represents the given color, specified in the HSB spectrum, in NetLogo's color space.
All three values should be in the range 0.0 to 1.0.
The color reported may be only an approximation, since the NetLogo color space does not include all possible colors. (It contains only certain discrete hues, and for each hue, either saturation or brightness may vary, but not both -- at least one of the two is always 1.0.)
show hsb 0 0 0 => 0.0 ;; (black) show hsb 0.5 1.0 1.0 => 85.0 ;; (cyan)
See also extract-hsb, rgb, extract-rgb.
This broadcasts value from NetLogo to the variable, in the case of Calculator HubNet, or interface element, in the case of Computer HubNet, with the name tag-name to the clients.
See the HubNet Authoring Guide for details and instructions.
This broadcasts the current state of the 2D view in the NetLogo model to all the Computer HubNet Clients. It does nothing for Calculator HubNet.
Note: This is an experimental primitive and its behavior may change in a future version.
See the HubNet Authoring Guide for details and instructions.
Reports true if a new computer client just entered the simulation. Reports false otherwise. hubnet-message-source will contain the user name of the client that just logged on.
See the HubNet Authoring Guide for details and instructions.
Reports true if a computer client just exited the simulation. Reports false otherwise. hubnet-message-source will contain the user name of the client that just logged off.
See the HubNet Authoring Guide for details and instructions.
If there is any new data sent by the clients, this retrieves the next piece of data, so that it can be accessed by hubnet-message, hubnet-message-source, and hubnet-message-tag. This will cause an error if there is no new data from the clients.
See the HubNet Authoring Guide for details.
Reports the message retrieved by hubnet-fetch-message.
See the HubNet Authoring Guide for details.
Reports the name of the client that sent the message retrieved by hubnet-fetch-message.
See the HubNet Authoring Guide for details.
Reports the tag that is associated with the data that was retrieved by hubnet-fetch-message. For Calculator HubNet, this will report one of the variable names set with the hubnet-set-client-interface primitive. For Computer HubNet, this will report one of the Display Names of the interface elements in the client interface.
See the HubNet Authoring Guide for details.
This looks for a new message sent by the clients. It reports true if there is one, and false if there is not.
See the HubNet Authoring Guide for details.
Starts up the HubNet system. HubNet must be started to use any of the other hubnet primitives with the exception of hubnet-set-client-interface.
See the HubNet Authoring Guide for details.
For Calculator HubNet, this primitive acts in exactly the same manner as hubnet-broadcast. (We plan to change this in a future version of NetLogo.)
For Computer HubNet, it acts as follows:
For a string, this sends value from NetLogo to the tag tag-name on the client that has string for its user name.
For a list-of-strings, this sends value from NetLogo to the tag tag-name on all the clients that have a user name that is in the list-of-strings.
Sending a message to a non-existent client, using hubnet-send, generates a hubnet-exit-message.
See the HubNet Authoring Guide for details.
For Calculator HubNet, does nothing.
For Computer HubNet, it acts as follows:
For a string, this sends the current state of the 2D view in the NetLogo model to the Computer HubNet Client with string for its user name.
For a list-of-strings, this sends the current state of the view in the NetLogo model to all the Computer HubNet Clients that have a user name that is in the list-of-strings.
Sending the 2D view to a non-existent client, using hubnet-send-view, generates a hubnet-exit-message.
Note: This is an experimental primitive and its behavior may change in a future version.
See the HubNet Authoring Guide for details.
If client-type is "COMPUTER", client-info is a list containing a string with the file name and path (relative to the model) to the file which will serve as the client's interface. This interface will be sent to any clients that log in.
hubnet-set-client-interface "COMPUTER" ["clients/Disease client.nlogo"] ;; when clients log in, they will will get the ;; interface described in the file ;; clients/Disease client.nlogo, relative to ;; the location of the model
Future versions of HubNet will support other client types. Even for Computer HubNet, the meaning of the second input to this command may change.
See the HubNet Authoring Guide for details.
Reporter must report a boolean (true or false) value.
If condition reports true, runs commands.
The reporter may report a different value for different agents, so some agents may run commands and others don't.
if xcor > 0[ set color blue ] ;; turtles on the right half of the view ;; turn blue
See also ifelse, ifelse-value.
Reporter must report a boolean (true or false) value.
If reporter reports true, runs commands1.
If reporter reports false, runs commands2.
The reporter may report a different value for different agents, so some agents may run commands1 while others run commands2.
ask patches
[ ifelse pxcor > 0
[ set pcolor blue ]
[ set pcolor red ] ]
;; the left half of the view turns red and
;; the right half turns blue
See also if, ifelse-value.
Reporter must report a boolean (true or false) value.
If reporter reports true, the result is the value of reporter1.
If reporter reports false, the result is the value of reporter2.
This can be used when a conditional is needed in the context of a reporter, where commands (such as ifelse) are not allowed.
ask patches
[ set pcolor
ifelse-value (pxcor > 0)
[ blue ]
[ red ] ]
;; the left half of the view turns red and
;; the right half turns blue
show n-values 10 [ifelse-value (? < 5) [0] [1]]
=> [0 0 0 0 0 1 1 1 1 1]
show reduce [ifelse-value (?1 > ?2) [?1] [?2]]
[1 3 2 5 3 8 3 2 1]
=> 8

Reads an image file into the drawing, scaling it to the size of the world, while retaining the original aspect ratio of the image. The image is centered in the drawing. The old drawing is not cleared first.
Agents cannot sense the drawing, so they cannot interact with or process images imported by import-drawing. If you need agents to sense an image, use import-pcolors.
The following image file formats are supported: BMP, JPG, GIF, and PNG. If the image format supports transparency (alpha), that information will be imported as well.

Reads an image file, scales it to the same dimensions as the patch grid while maintaining the original aspect ratio of the image, and transfers the resulting pixel colors to the patches. The image is centered in the patch grid. The resulting patch colors may be distorted, since the NetLogo color space does not include all possible colors. (See the Color section of the Programming Guide.) import-pcolors may be slow for some images, particularly when you have many patches and a large image with many different colors.
Since import-pcolors sets the pcolor of patches, agents can sense the image. This is useful if agents need to analyze, process, or otherwise interact with the image. If you want to simply display a static backdrop, without color distortion, see import-drawing.
The following image file formats are supported: BMP, JPG, GIF, and PNG. If the image format supports transparency (alpha), then all fully transparent pixels will be ignored. (Partially transparent pixels will be treated as opaque.)

Reads the values of all variables for a model, both built-in and user-defined, including all observer, turtle, and patch variables, from an external file named by the given string. The file should be in the format used by the export-world primitive.
Note that the functionality of this primitive is also directly available from NetLogo's File menu.
When using import-world, to avoid errors, perform these steps in the following order:
If you wish to import a file from a location other than the model's location, you may include the full path to the file you wish to import. See export-world for an example.

This reporter lets you give a turtle a "cone of vision" in front of itself. The cone is defined by the two inputs, the vision distance (radius) and the view angle. The view angle may range from 0 to 360 and is centered around the turtle's current heading. (If the angle is 360, then in-cone is equivalent to in-radius.)
in-cone reports an agentset that includes only those agents from the original agentset that fall in the cone including the agent itself.
The distance to a patch is measured from the center of the patch.
ask turtles
[ ask patches in-cone 3 60
[ set pcolor red ] ]
;; each turtle makes a red "splotch" of patches in a 60 degree
;; cone of radius 3 ahead of itself
Reports true if there is a link going from agent to the caller.
to check-friendship-neighbors
ca
cct-turtles 2[]
ask turtle 0
[
__create-link-to turtle 1[]
show __in-link-neighbor? turtle 1 ;; prints false
show __out-link-neighbor? turtle 1 ;; prints true
]
ask turtle 1
[
show __in-link-neighbor? turtle 0 ;; prints true
show __out-link-neighbor? turtle 0 ;; prints false
]
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports the agentset of all the node turtles that have links coming from them to the caller.
breed [links link] ;; breed for network links to become-friendly ;; node procedure __create-links-to friends [] show __out-link-neighbors ;; prints the agentset of friends end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Report the link turtle from the agent to the caller. If no link exists then it reports nobody.
to find-friendship-with
ca
cct 2 []
ask turtle 0
[
__create-link-to turtle 1 []
__create-link-from turtle 1 []
show __in-link-from turtle 1 ;; prints turtle 3
show __out-link-to turtle 1 ;; prints turtle 2
show __link-with turtle 1 ;; prints turtle 2
]
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

Reports an agentset that includes only those agents from the original agentset whose distance from the caller is less than or equal to number, including the caller itself if wrapping is allowed by the topology members of the agentset within the radius using the wrapped distance will be included.
The distance to or a from a patch is measured from the center of the patch.
ask turtles
[ ask patches in-radius 3
[ set pcolor red ] ]
;; each turtle makes a red "splotch" around itself
Opens an agent monitor for the given agent (turtle or patch).
inspect patch 2 4 ;; an agent monitor opens for that patch inspect one-of sheep ;; an agent monitor opens for a random turtle from ;; the "sheep" breed
Reports the integer part of number -- any fractional part is discarded.
show int 4.7 => 4 show int -3.5 => -3
Reports true if value is of the given type, false otherwise.
On lists, reports the value of the item in the given list with the given index.
On strings, reports the character in the given string at the given index.
Note that the indices begin from 0, not 1. (The first item is item 0, the second item is item 1, and so on.)
;; suppose mylist is [2 4 6 8 10] show item 2 mylist => 6 show item 3 "my-shoe" => "s"
The __is-link? reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

Turtles move forward by number units all at once, without the number of turns it takes depending on the distance.
This command is useful for synchronizing turtle movements. A turtle takes 15 turns to do fd 15, but only one turn to do jump 15.
If the turtle cannot jump number units because it is not permitted by the current topology the turtle does not move at all.
Note: When turtles jump, they do not step on any of the patches along their path.

This is a built-in turtle variable. It may hold a value of any type. The turtle appears in the view with the given value "attached" to it as text. You can set this variable to add, change, or remove a turtle's label.
See also label-color, plabel, plabel-color.
Example:
ask turtles [ set label who ] ;; all the turtles now are labeled with their ;; id numbers ask turtles [ set label "" ] ;; all turtles now are not labeled

This is a built-in turtle variable. It holds a number greater than or equal to 0 and less than 140. This number determines what color the turtle's label appears in (if it has a label). You can set this variable to change the color of a turtle's label.
See also label, plabel, plabel-color.
Example:
ask turtles [ set label-color red ] ;; all the turtles now have red labels
On a list, reports the last item in the list.
On a string, reports a one-character string containing only the last character of the original string.
Arranges the given turtles in a circle centered on the patch at the center of the world with the given radius. (If the world has an even size the center of the circle is rounded down to the nearest patch.) The turtles point outwards.
If the first input is an agentset, the turtles are arranged in random order.
If the first input is a list, the turtles are arranged clockwise in the given order, starting at the top of the circle. (Any non-turtles in the list are ignored.)
;; in random order __layout-circle turtles 10 ;; in order by who number __layout-circle sort turtles 10 ;; in order by size __layout-circle sort-by [size-of ?1 < size-of ?2] turtles 10
Very similar to __layout-spring, but with an added layer of complexity. The agentset of turtles attract and repel each other depending on the links between them, but there is also a magnetic field which the links try to align with.
anchor-agentset is a set of turtles whose positions remain fixed. (If no turtles are anchored down, then they will often all slide off to the side of the view!)
spring-constant is a measure of the "tautness" of the spring. (See __layout-spring)
spring-length is the "zero-force" length or the natural length of the springs. (See __layout-spring)
repulsion-constant is a measure of repulsion between the nodes. (See __layout-spring)
magnetic-field-strength is the force of the magnetic field. (Reasonable values range from 0.0 to 1.0, but 0.05 is a good default.)
magnetic-field-type is a number in the range from 0 to 10. Choices are listed in the table below.
| magnetic-field-type | Description |
| NONE = 0 | If no field is used, then this command works just like layout-spring. |
| NORTH = 1 | Magnetic field runs toward the North |
| NORTHEAST = 2 | Magnetic field runs toward the Northeast |
| EAST = 3 | ... |
| SOUTHEAST= 4 | ... |
| SOUTH = 5 | ... |
| SOUTHWEST= 6 | ... |
| WEST = 7 | ... |
| NORTHWEST = 8 | ... |
| POLAR = 9 | Magnetic field runs outward at all angles from the origin. |
| CONCENTRIC = 10 |
Magnetic field runs clockwise around the origin in concentric circles. |
If bidirectional? is true then links try to align with the magnetic field by pushing attached turtles both in the direction of the field, and in the opposite direction. Otherwise, the links just push in a single direction.
breed [links link]
breed[nodes node]
to make-a-tree
set-default-shape nodes "circle"
create-custom-nodes 5 []
ask turtle 0
[
__create-link-with turtle 1 []
__create-link-with turtle 2 []
]
ask turtle 1
[
__create-link-with turtle 3 []
__create-link-with turtle 4 []
]
; one turtle (the root of the tree) is our anchor-set
let anchor-set (turtles with [ who = 0])
; layout with a fairly strong SOUTH magnetic field
repeat 50 [ __layout-magspring
nodes anchor-set 0.3 4 1.0 .50 5 false ]
end
This command is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Arranges the agentset of turtles, agentset, in a radial tree layout, centered around root-agent.
Only links of the given breed will be used to determine the layout. (Useful if you have multiple link breeds in one model.)
Even if the network does contain cycles, and is not a true tree structure, this layout will still work, although the results will not always be pretty.
If agentset is an agentset of patches, an error is thrown.
breed [links link]
to make-a-tree
set-default-shape turtles "circle"
cct 6 []
ask turtle 0
[
__create-link-with turtle 1 []
__create-link-with turtle 2 []
__create-link-with turtle 3 []
]
ask turtle 1
[
__create-link-with turtle 4 []
__create-link-with turtle 5 []
]
; do a radial tree layout, centered on turtle 0
__layout-radial turtles (turtle 0) links
end
This command is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Arranges the agentset of turtles, agentset, as if the links with which they are connected to each other were springs and the nodes were repelling each other.
spring-constant is a measure of the "tautness" of the spring. It is the "resistance" to change in their length. spring-constant is the force the spring would exert if it's length were changed by 1 unit.
spring-length is the "zero-force" length or the natural length of the springs. This is the length which all springs try to achieve either by pushing out their nodes or pulling them in.
repulsion-constant is a measure of repulsion between the nodes. It is the force that 2 nodes at a distance of 1 unit will exert on each other.
The repulsion effect tries to get the nodes as far as possible from each other, in order to avoid crowding and the spring effect tries to keep them at "about" a certain distance from the nodes they are connected to. The result is the laying out of the whole network in a way which highlights relationships among the nodes and at the same time is crowded less and is visually pleasing.
If agentset is an agentset of patches, an error is thrown.
The layout algorithm is based on the Fruchterman-Reingold layout algorithm. More information about this algorithm can be obtained here.
breed [links link]
breed [nodes node]
to make-a-triangle
set-default-shape nodes "circle"
create-custom-nodes 3 []
ask turtle 0
[
__create-links-with turtles with [ who-of self != 0 ]
[]
]
ask turtle 1
[
__create-link-with turtle 2
[]
]
repeat 30 [__layout-spring nodes 0.2 5 1] ;; lays the nodes in a triangle
end
This command is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
The turtles in anchor-agentset are placed in a circle layout with the given radius. There should be at least 3 agents in the anchor-agentset.
The turtles in agentset (unless they are also members of anchor-agentset) are then laid out in the following manner: Each turtle is placed at centroid (or barycenter) of the polygon formed by its linked neighbors. (The centroid is like a 2-dimensional average of the coordinates of the neighbors.)
(The purpose of the circle of anchor-agentset is to prevent all the turtles from collapsing down to one point.)
After a few iterations of this, the layout will stabilize.
If agentset is an agentset of patches, an error is thrown.
This layout is named after the mathematician William Thomas Tutte, who proposed it as a method for graph layout.
breed [links link ]
to make-a-tree
set-default-shape turtles "circle"
cct 6 []
ask turtle 0
[
__create-link-with turtle 1 []
__create-link-with turtle 2 []
__create-link-with turtle 3 []
]
ask turtle 1
[
__create-link-with turtle 4 []
__create-link-with turtle 5 []
]
; place all the turtles with just one
; neighbor on the perimeter of a circle
; and then place the remaining turtles inside
; this circle, spread between their neighbors.
repeat 10 [ __layout-tutte turtles
(turtles with [ count __link-neighbors = 1]) 12.0 ]
end
This command is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

The turtle turns left by number degrees. (If number is negative, it turns right.)
Reports the number of items in the given list, or the number of characters in the given string.
Creates a new local variable and gives it the given value. A local variable is one that exists only within the enclosing block of commands.
If you want to change the value afterwards, use set.
Example:
let prey one-of sheep-here if prey != nobody [ ask prey [ die ] ]
Reports a list containing the given items. The items can be of any type, produced by any kind of reporter.
show list (random 10) (random 10) => [4 9] ;; or similar list show (list 5) => [5] show (list (random 10) 1 2 3 (random 10)) => [4 1 2 3 9] ;; or similar list
Reports the natural logarithm of number, that is, the logarithm to the base e (2.71828...).
NOTE: This keyword should not be used in new models. Please use the let command instead. "locals" is included only for backwards compatibility with NetLogo version 2.0 and earlier. It will not necessarily continue to be supported in future versions of NetLogo.
Locals is a keyword used to declare "local" variables in a procedure, that is, variables that are usable only within that procedure. It must appear at the beginning of the procedure, before any commands.
See also let.
Reports the logarithm of number in base base.
show log 64 2 => 6
See also ln.
Runs the list of commands forever, or until the current procedure exits through use of the stop command or the report command.
Note: In most circumstances, you should use a forever button in order to repeat something forever. The advantage of using a forever button is that the user can click the button to stop the loop.
Adds value to the end of a list and reports the new list.
;; suppose mylist is [2 7 10 "Bob"] set mylist lput 42 mylist ;; mylist now is [2 7 10 "Bob" 42]
With a single list, the given reporter is run for each item in the list, and a list of the results is collected and reported.
In reporter, use ? to refer to the current item of list.
show map [round ?] [1.1 2.2 2.7] => [1 2 3] show map [? * ?] [1 2 3] => [1 4 9]
With multiple lists, the given reporter is run for each group of items from each list. So, it is run once for the first items, once for the second items, and so on. All the lists must be the same length.
In reporter, use ?1 through ?n to refer to the current item of each list.
Some examples make this clearer:
show (map [?1 + ?2] [1 2 3] [2 4 6]) => [3 6 9] show (map [?1 + ?2 = ?3] [1 2 3] [2 4 6] [3 5 9]) => [true false true]
Reports the maximum number value in the list. It ignores other types of items.
show max values-from turtles [xcor] ;; prints the x coordinate of the turtle which is ;; farthest right in the view
Reports the agent in the agentset that has the highest value for the given reporter. If there is a tie this command reports one random agent with the highest value. If you want all such agents, use with-max instead.
show max-one-of patches [count turtles-here]
;; prints the first patch with the most turtles on it
See also with-max
These reporters give the maximum x-coordinate and maximum y-coordinate, (respectively) for patches, which determines the size of the world.
Unlike in older versions of NetLogo the origin does not have to be at the center of the world. However, the maximum x- and y- coordinates must be greater than or equal to zero.
Note: You can set the size of the world only by editing the view -- these are reporters which cannot be set.
cct 100 [ setxy random-float max-pxcor
random-float max-pycor ]
;; distributes 100 turtles randomly in the
;; first quadrant
See also min-pxcor, min-pycor, world-width, and world-height
Reports the statistical mean of the numeric items in the given list. Ignores non-numeric items. The mean is the average, i.e., the sum of the items divided by the total number of items.
show mean values-from turtles [xcor] ;; prints the average of all the turtles' x coordinates
Reports the statistical median of the numeric items of the given list. Ignores non-numeric items. The median is the item that would be in the middle if all the items were arranged in order. (If two items would be in the middle, the median is the average of the two.)
show median values-from turtles [xcor] ;; prints the median of all the turtles' x coordinates
For a list, reports true if the given value appears in the given list, otherwise reports false.
For a string, reports true or false depending on whether string1 appears anywhere inside string2 as a substring.
For an agentset, reports true if the given agent is appears in the given agentset, otherwise reports false.
show member? 2 [1 2 3] => true show member? 4 [1 2 3] => false show member? "rin" "string" => true show member? turtle 0 turtles => true show member? turtle 0 patches => false
See also position.
Reports the minimum number value in the list. It ignores other types of items.
show min values-from turtles [xcor] ;; prints the lowest x-coordinate of all the turtles
Reports a random agent in the agentset that reports the lowest value for the given reporter. If there is a tie, this command reports one random agent that meets the condition. If you want all such agents use with-min instead.
show min-one-of turtles [xcor + ycor] ;; reports the first turtle with the smallest sum of ;; coordinates
See also with-min
These reporters give the minimum x-coordinate and minimum y-coordinate, (respectively) for patches, which determines the size of the world.
Unlike in older versions of NetLogo the origin does not have to be at the center of the world. However, the minimum x- and y- coordinates must be less than or equal to zero.
Note: You can set the size of the world only by editing the view -- these are reporters which cannot be set.
cct 100 [ setxy random-float min-pxcor
random-float min-pycor ]
;; distributes 100 turtles randomly in the
;; third quadrant
See also max-pxcor, max-pycor, world-width, and world-height
Reports number1 modulo number2: that is, the residue of number1 (mod number2). mod is is equivalent to the following NetLogo code:
number1 - (floor (number1 / number2)) * number2
Note that mod is "infix", that is, it comes between its two inputs.
show 62 mod 5 => 2 show -8 mod 3 => 1
See also remainder. mod and remainder behave the same for positive numbers, but differently for negative numbers.
Reports a list of the most common item or items in list.
The input list may contain any NetLogo values.
If the input is an empty list, reports an empty list.
show modes [1 2 2 3 4] => [2] show modes [1 2 2 3 3 4] => [2 3] show modes [ [1 2 [3]] [1 2 [3]] [2 3 4] ] => [[1 2 [3]] show modes values-from turtles [pxcor] ;; shows which columns of patches have the most ;; turtles on them
Reports true if the mouse button is down, false otherwise.
Note: If the mouse pointer is outside of the current view , mouse-down? will always report false.
Reports true if the mouse pointer is inside the current view, false otherwise.
Reports the x or y coordinate of the mouse in the 2D view. The value is in terms of turtle coordinates, so it is a floating-point number. If you want patch coordinates, use round mouse-xcor and round mouse-ycor.
Note: If the mouse is outside of the 2D view, reports the value from the last time it was inside.
;; to make the mouse "draw" in red: if mouse-down? [ set pcolor-of patch-at mouse-xcor mouse-ycor red ]
Cancels the current movie.
Stops the recording of the current movie.
Adds an image of the current view or the interface panel to the current movie.
;; make a 20-step movie of the current view setup movie-start "out.mov" repeat 20 [ movie-grab-view go ] movie-close
Sets the frame rate of the current movie. The frame rate is measured in frames per second. (If you do not explicitly set the frame rate, it defaults to 15 frames per second.)
Must be called after movie-start, but before movie-grab-view or movie-grab-interface.
See also movie-status.
Creates a new movie. filename specifies a new QuickTime file
where the movie will be saved, so it should end with ".mov".
See also movie-grab-view, movie-grab-interface, movie-cancel, movie-status, movie-set-frame-rate, movie-close.
Reports a string describing the current movie.
print movie-status => No movie. movie-start print movie-status => 0 frames; Framerate = 15.0. movie-grab-view print movie-status 1 frames; Framerate = 15.0; Size = 315x315.
Reports an agentset of all links coming in from other nodes to the caller.
breed [links link] ;; breed for network links
to become-friendly ;; node procedure
__create-links-with other-turtles
[]
show __my-links ;; prints the agentset of link turtles that connecting
;; with this node.
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports an agentset of all the directed links coming in from other nodes to the caller.
breed [links link] ;; breed for network links
to become-friendly ;; node procedure
__create-links-to other-turtles
[]
show __my-in-links ;; prints the agentset of link turtles that connect
;; to this node
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports an agentset of all the directed links going out from the caller to other nodes.
breed [links link] ;; breed for network links
to become-friendly ;; node procedure
__create-links-to other-turtles
[]
show __my-out-links ;; prints the agentset of link turtles that connect
;; from this node
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.

"self" and "myself" are very different. "self" is simple; it means "me". "myself" means "the turtle or patch who asked me to do what I'm doing right now."
When an agent has been asked to run some code, using myself in that code reports the agent (turtle or patch) that did the asking.
myself is most often used in conjunction with -of to read or set variables in the asking agent.
myself can be used within blocks of code not just in the ask command, but also hatch, sprout, values-from, value-from, turtles-from, patches-from, histogram-from, with, min-one-of, and max-one-of.
ask turtles
[ ask patches in-radius 3
[ set pcolor color-of myself ] ]
;; each turtle makes a colored "splotch" around itself
See the "Myself Example" code example for more examples.
See also self.
From an agentset, reports an agentset of size size randomly chosen from the input set, with no repeats.
From a list, reports a list of size size randomly chosen from the input set, with no repeats. The items in the result appear in the same order that they appeared in the input list. (If you want them in random order, use shuffle on the result.)
It is an error for size to be greater than the size of the input.
ask n-of 50 patches [ set pcolor green ] ;; 50 randomly chosen patches turn green
See also one-of.
Reports a list of length size containing values computed by repeatedly running reporter.
In reporter, use ? to refer to the number of the item currently being computed, starting from zero.
show n-values 5 [1] => [1 1 1 1 1] show n-values 5 [?] => [0 1 2 3 4] show n-values 3 [turtle ?] => [(turtle 0) (turtle 1) (turtle 2)] show n-values 5 [? * ?] => [0 1 4 9 16]

Reports an agentset containing the 8 surrounding patches (neighbors) or 4 surrounding patches (neighbors4).
show sum values-from neighbors [count turtles-here] ;; prints the total number of turtles on the eight ;; patches around the calling turtle or patch ask neighbors4 [ set pcolor red ] ;; turns the four neighboring patches red
Reports the agentset of all the node turtles that have links coming from them to the caller, or coming from the caller to them.
breed [links link] ;; breed for network links
to become-friendly ;; node procedure
__create-links-to friends
[]
show __link-neighbors ;; prints the agentset of agents who are
;; "friends" with, or whom it is "friends" with
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports true if there is a link going from agent to the caller, or from the caller to agent.
to check-friendship-neighbors
ca
cct-turtles 2[]
ask turtle 0
[
__create-link-to turtle 1[]
show __in-link-neighbor? turtle 1 ;; prints false
show __out-link-neighbor? turtle 1 ;; prints true
show __link-neighbor? turtle 1 ;; prints true
]
ask turtle 1
[
show __in-link-neighbor? turtle 0 ;; prints true
show __out-link-neighbor? turtle 0 ;; prints false
show __link-neighbor? turtle 0 ;; prints true
]
end
This reporter is part of the experimental Links support in NetLogo. See the Links section of the Programming Guide for more details.
Reports a string containing the version number of the NetLogo you are running.
show netlogo-version => "3.1.5"
Reports a number suitable for seeding the random number generator.
The numbers reported by new-seed are based on the current date and time in milliseconds and lie in the range -2147483648 to 2147483647.
new-seed never reports the same number twice in succession. (This is accomplished by waiting a millisecond if the seed for the current millisecond was already used.)
See also random-seed.
Turns off all updates to the current view until the display command is issued. This has two major uses.
One, you can control when the user sees view updates. You might want to change lots of things on the view behind the user's back, so to speak, then make them visible to the user all at once.
Two, your model will run faster when view updating is off, so if you're in a hurry, this command will let you get results faster. (Note that normally you don't need to use no-display for this, since y