Today, we're going to spend some time
talking about the interface tab in NetLogo
and primarily how you can design a good
interface for your model.
So here we're looking at the NetLogo 'Fire'
model...
which you probably remember from the
beginning of the course,
and you'll notice right away when you look
at the interface tab
that there are two buttons that almost
always appear on every interface
in the NetLogo models library.
That's the setup button and the go button.
In the next set of lectures, when we talk
about how you write your code,
we'll explain that these are basically
the standard way in NetLogo -
- again NetLogo style not syntax -
of controlling the model run.
So you almost always have a setup command
to initialise the model
and a go command that allows the model
to run.
And to do that, you'll see these buttons here,
And to create them, you just go up and you
select 'button', hit 'add', click someplace,
and you can type in the command that you
want that button to execute.
You can also give it your own display command
as well, like 'my setup', or something like that.
And this will then execute the code.
So 'setup' now executes the same code as
this 'my setup',
even though the name of it is different.
And then you can always edit or delete by
right-clicking or control-clicking...
and then you can either select it and move it
around...
you can edit it again if you want to change
what it says...
or you can just delete it.
So that's buttons.
In fact, there are a number of different interface
elements you can automatically create in NetLogo...
buttons being one of them. There are two
others here in the NetLogo 'Fire' model...
the slider, which allows you to specify a
particular value for a global variable,
and a monitor, which allows NetLogo to present
results back to you in terms of what's going on.
Let's talk about those.
The slider in this case controls the
density of the trees in the world
and if you right-click on it you can see that
it has a property of having a minimum value,
an increment, a maximum value, a value
at the initial start of a run
and units, this is just what displays right
here, so you could say 'percentage trees'.
You can also make the slider vertical if you
want, as opposed to horizontal,
and then this is the name, the name of the
global variable that the slider controls.
Now for the monitor, if you right-click on
it,
you'll see that it is actually a piece of code,
and what it's doing is taking the variable
'burned-trees', the number of burned trees...
dividing it by the number of initial-trees, and
multiplying by a hundred...
to get the percentage that are burned trees.
And then you can specify the display name,
how many decimal places are displayed...
and what size to put it in.
So there are three of the elements. And if you
look up here again you'll notice...
that there is one element which is purple,
which is buttons
because they are directly interacting with the
model run.
There are four that are green: these are things
that control inputs to the model.
And then there's three more that are tan, and
one that's a kind of white.
The tan ones are ones that allow NetLogo to
output results.
And the white one, note, is just a predefined
note that you can place anywhere,
so you can describe things, for
instance, 'this is my note',
just to illustrate and document the model.
So the 'Fire' model has a slider, a button
and a monitor.
Another interesting model to look at would
be the 'Segregation' model.
So if we go to 'Social Science' and load up the
'Segregation' model we've previously looked at...
You'll see this has sliders and buttons,
and again has a setup and go.
You'll also notice that the go is greyed out, and
won't turn regular until after you've hit setup.
This is because you can disable the button until
'ticks' start,
which we'll talk about in the next couple of days.
But besides these, there are also some other
interesting things here.
There is a plot, which is plotting
results,
There are monitors as well, as we saw before.
And then there is a chooser that allows you
to choose particular values...
So this chooser actually lets you choose
whether the visualisation is the classic turtles
or the new square 'X', so you can choose
which one you want.
Finally, I wanted to show you one other, which
is the 'Voting' model,
because the 'Voting' model uses the last simple
type of input to the model which we often see,
which is the boolean switch.
The boolean switch controls whether
a variable is true or false.
So in this case, we are looking at a model of
votes where people look at their neighbours...
to decide which colour to be, blue or green,
based upon what their friends are.
And these boolean switches allows you to
change their behaviour.
So this one allows you to say 'they should change
their vote if there's an equal number of people tied'
and this one says 'if it's a close call, for instance,
if it's 5 to 3 one way of the other...
they should change their vote'
And if you look at these, all you're specifying
is the name of the global variable,
and all global variables that have booleans
in NetLogo always end in a question mark ('?')
and so you'll always see that in that particular
context.
And then these variables can be accessed
directly within the NetLogo code...
which, as I mentioned, we'll talk about
in a little bit.
There are a couple of other things we didn't
mention...
we didn't mention text input, that's a little
more complex,
you can look that up in the NetLogo manual.
output, this is a textual output, that you
can also look up and explore on your own.
But the main ones you're going to use are
probably button, slider, switch, chooser
and then monitors and plots.
We'll get into more detail about how to
build the plots,
because they're a little more complex, in
a future lesson.
There's a couple of last elements I want to
talk about about the interface tab.
One of them, you may have played around
with a little bit before, is the speed slider.
It's this little slider up here that allows you to
control the speed of the models.
So we hit 'setup' and then what we can do,
if we want to see the model run a little slower,
is we can move it down, and then what will
happen is that the updates of the graphical image...
of the model are going to happen at a slower
speed,
And, if we want, we can speed up the model,
and allow it to run faster.
And if we move it all the way up, what happens
is we see very few of the actual updates,
and so we just see, in this case, the end results.
And if we make the model a little denser, then
we see one interim picture before the final results.
You can tell NetLogo whether you only want
to view the updates on 'ticks' or 'continuous',
And essentially the speed slider is allowing you
to vary how quickly you're seeing those updates.
It's a useful tool especially when you're
debugging, to play around with the speed slider
The other thing I want to discuss with regards
to the interface is the world properties tab
or the model settings tab.
It's found by right-clicking on the background
of the model...
or you can click the 'Settings' button up here...
And this allows you to control the dimensions
of your world first and foremost...
So, in the 'Fire' case, we've set the middle
of the world to be '0, 0'
with the boundaries being the appropriate
ones away from that,
so the max coordinate is 125.
But you can, for instance, move the centre
of the world - the '0, 0' coordinate -
to a corner, for instance the bottom left,
which is standard looking at the first quadrant
of most Cartesian graphs
You could put it at an edge, so now it's in
the middle at the bottom,
or you can actually set the location of the
centre of the world to any place you want,
just by telling it what you want the
minimum and maximum pxcor and pycor to be.
min-pxcor, max-pxcor, min-pycor and max-pycor,
which we'll explain in the next set of lectures...
are the minimum and maximum patch x and y
coordinates.
One other thing you'll see here,
say you want a bigger world
You want more trees, to see if the results
depend upon the size of the world.
We can, for instance, change the max-pxcor
and max-pycor to something much bigger...
but when we do that, you can see it's now
exploded beyond the size that you can see here.
One way we can fix that is - you see the
patch size was set to '2' -
If I set it back to '1' it will at least bring some
of it back into view.
The patch size parameter controls how many
pixels each patch is the size of.
We'll talk more about patches in the next
couple of days.
Besides that, we can also control the font
size, which is the size of the different characters,
the frame rate, how many frames we'll see,
And whether we show the tick counter,
which we'll talk about in the next couple of days,
and how the tick counter is actually labelled.
So in the 'Fire' model if each timestep is
roughly an hour...
we can actually change it to 'hours' as opposed
to 'ticks'.
There's one last element of the model settings
I wanted to discuss
and that is these wrapping buttons. To explore
these, I brought up the 'Flocking' model.
What I want you to notice is that, if you run
the 'Flocking' model, if you watch carefully,
any birds that fly off one side of the screen
appear on the other side.
This is sometimes called the 'pacman' world,
because as pacman goes off one side he
comes back on the other,
and we call this 'world wrapping' in NetLogo.
You can make this very clear, if I pause the model,
and I go up here...
and I watch this turtle right here... it will highlight
a little grey circle around...
and now as you can see, as that particular bird
moves across the world...
we can see that it just went off one side and
appeared on the other.
That is because we have world wrapping on,
so the world wraps horizontally and vertically.
If we turn world wrapping off, what you'll
see will be very interesting...
in the flocking model what happens is that
the birds fly to the edges of the world...
and just get stuck there.
And that's because at that point, they no
longer have any rules as to what to do...
and once they get stuck at the edge of the world
then NetLogo won't allow them to go past.
So this is another thing to consider. On some
models you want to have world wrapping on,
in some models you don't what to have it on
And you can make the decision as you chose.
And, by the way, you can also have it only on
for part of the world...
either horizontally or vertically.
So in this case I've turned it on just
horizontally
so the birds can move this across the left and
right edges,
they can't move across the top or bottom.
So that's it for the interface tab.
In the next set of discussions we're going to
be talking about the code tab.