We've talked about turtles which are the basic mobile agent
and probably the agents that you'll use the most often within your NetLogo models
but there are two other types of agents that exist within the NetLogo space.
One is the patches. Patches are the immobile background objects...
that exist behind every space of the world.
They may not be obvious, because they're all black,
but the world that you're seeing here is actually composed of many different patches.
We can address them much like we address the turtles
by saying 'ask patches' to do something.
The patches, much like the turtles, have a color,
So we can set their pcolor which is their patch color -
we'll explain in a second why that's different from color for the turtles -
we can set their pcolor to be a particular value.
So one thing we could do is set their pcolor to depend on their x and y coordinates
and for the patches that's pxcor and pycor.
So in this case I'm asking the patches to set their pcolor
to be pxcor times pycor: 'ask patches [ set pcolor pxcor * pycor ]'
and when I hit 'enter' you'll now see that the patches are there fairly obviously,
and that there are a number of different ones in the space.
In fact, if you remember back to the first subunit of this unit,
we discussed how you can modify the settings of the world...
in order to make more or less patches within the world.
So we can use the patches in much the same way we use turtles,
they have properties, we can look at them, we can manipulate those properties.
We can inspect one of the patches and then we can see what properties it has.
a pxcor, pycor, pcolor, plabel and a plabel-color.
What's interesting about patches in terms of their interaction with turtles...
is that turtles have direct access to all the different patch variables.
So, for instance, we can create a bunch of turtles now, 'crt 100',
and we can ask those turtles to go to a random xcor and ycor:
'ask turtles [ setxy random-xcor random-ycor ]'
so now they're scattered across the screen,
and now we can have the turtles set the patch variables,
so we can ask the turtles to set the patch color to their own color:
'ask turtles [ set pcolor color ]'
The reason why this works is because every turtle can only ever be on one patch at a time
so it only has access to one set of patch variables.
This is why the color variable for the turtle is named something different
from the patch color variable.
By the way, in addition to random-xcor and random-ycor
there is also random-pxcor and random-pycor
which will give you random patch coordinates
and those are at the centre of the patches.
We can also use patches in a different way -
so let's set all the patches back to black 'ask patches [ set pcolor black ]'.
We could, for instance, have turtles find their NetLogo patches
so we could ask the turtles to facexy - which means face a particular x,y coordinate
and we're going to have them face the coordinates of their current patch:
'ask turtles [ facexy pxcor pycor ]'
so this is aiming them at the centre of the patch they happen to be standing on.
So in this way we can have turtles and patches interact.
They can work together in interesting ways
and you can use patches to manipulate the actions of your turtles.
In addition to patches there is one last agent type that exists -
we won't spend a lot of time talking this now but I want you to know about it.
This is the link agent type.
The link agent type allows us to move beyond having physical attributes of the turtles...
to having network based attributes.
We can ask the turtles to create a link with one of the other turtles:
'ask turtles [ create-link-with one-of other turtles ]'
and what you now see is they've all created links.
That command was a little complex, so let me dissect it a bit,
so we ask each turtle to create-link-with, to create a singular link with...
one-of, which basically takes a random element of a set...
other turtles, which takes the set of all turtles and removes the turtle that's currently calling it
and just looks at the other turtles, so it's saying...
'create a link with one of the other turtles'.
A nice thing about NetLogo is that often the English interpretation of the phrase...
is actually the way the model will run.
Now here I'm creating an undirected link.
But you could create a directed link, that command is 'create-link-to' another turtle
or 'create-link-from' one of the other turtles.
And I can create multiple links at the same time,
so I can 'create-links-with' n-of the other turtles, rather than 'create-link-with'.
One last comment is that links are fully fledged agents,
just like turtles and patches,
so I can look at the properties of links.
One of the properties is the ends, so we can see which turtles they connect,
the color, the label, etc.
So those are the three basic agents in NetLogo,
turtles being the most basic and most common type you're going to work with,
but patches and links are very important
and have many of the same properties and abilities as turtles.