NetLogo Initializing Turtles at Specific Co-Ordinates - netlogo

in a NetLogo model, I have some "plant" turtles in a space. The number of which is 5, and will always be 5.
set-default-shape plants "plant"
create-plants 10
[
set color green
set size 2
setxy random-xcor random-ycor
setxy random-xcor random-ycor
]
At the moment each of these plants randomly spawns in the world. I want to be able to set the point at which each of these plants is placed.
Something akin to:
setxy plant-1 25 25
setxy plant-2 25 25
Is there any way to achieve this?

Currently, the line setxy random-xcor random-ycor is setting the x-coordinate and y-coordinate of the plants to random values. Note that you seem to have that line in your code twice. The first instance of it gets overwritten by the second. Anyway, you can also use setxy to move plants to particularly coordinates, e.g. setxy 25 25. However, replacing setxy random-xcor random-ycor with setxy 25 25 would put all the plants at that location. I assume you want multiple plants in multiple specific locations. To do that, you can just ask the individual plants to move:
ask plant 0 [ setxy 25 25 ]
ask plant 1 [ setxy 10 40 ]
and so forth.

Related

how to use a global variable to create turtle inside a population that has already been created using another global variable

Create a number of infected turtles in each population (brown and magenta) determined by the global variable initially_infected. For example if initially_infected is set to 10 there would be 10 individuals in the brown population infected and 10 individuals in the magenta population infected.
to initialise_agents
create-turtles magenta_population[
set color yellow
set size 1
setxy random-xcor random-ycor
move-to one-of patches with [pcolor = magenta]]
create-turtles brown_population[
set color yellow
set size 1
setxy random-xcor random-ycor
move-to one-of patches with [pcolor = brown]
]
now I need to change color of 10 turtles in both the magenta and brown population, but it shpuld be determined by the global variable initially_infected
I am new to netlogo. Unfortunately, I got an assignment from my university. the question is:
In this project you will be developing a model to ascertain important factors the impact the spread of an infectious disease among a population of agents within a particular timeframe. You will have 2 populations of agents that are infected with a virus which will spread among the populations. You will analyse factors that impact the spread and mortality rate such as population density, social distancing, self-isolation and the amount of time the virus can go undetected whist transmissible.
Since it is an assignment, I prefer not giving full answers (how else are you supposed to learn).
But you might want to take a look at the n-of primitive

Initializing turtles along a horizontal axis

I'm trying to setup turtles in a Netlogo model where the turtles are arranged randomly along the x-axis (from -16 to 16 on the interface) and along the y-axis at -16. Essentially across the bottom of the interface.
I've tried setxy xcor -16 16 ycor -16 but get "expected command" when checking the code.
Any thoughts would be appreciated.
If you look at the NetLogo Dictionary for setxy, one of the examples is:
setxy random-xcor random-ycor
That places the turtle in a random location. You want the ycor to be -16, so this would work:
setxy random-xcor -16.5
Even better, if you want to be able to adjust your world size and always be along the bottom, then:
setxy random-xcor min-pycor - 0.5
You may want to adjust the 0.5 a little to get them slightly off the bottom.

setting up turtles with preset distance between them (netlogo)

I am a high school student and I have to make a model about plants and plagues. I want to setup turtles with a preset distance from each other, but I can't figure out how to do that without creating an infinite loop. This is what my code looks like. Now it creates 20 turtles with random distance between them, but I want them to have a preset distance and as much turtles there can be on the screen with that distance between them.
to setup
clear-all
ask patches [ set pcolor 33 ]
make
repeat 20 [maken]
reset-ticks
end
to make
create-aardappelplanten 1[
setxy random-xcor random-ycor
set color green
set size 1.5
set shape "plant"
set age 1
]
end
Thank you so much!!

How to spawn simultaniously turtles in netlogo

Is there a way to spawn turtles during simulation even if they died. In my simulation fish are eating plankton, so if they encounter plankton the plankton dies/gets eaten. However, when a fish can't eat plankton anymore it will die because it doesn't get energy from plankton anymore by eating it. So when all the fish have died the plankton should come back; due to migration etc. and grow immensively. I am not sure how to implement this? The create function doesn't work here, only in the setup.
to plankton-reproduce
if random-float 100 < reproduce-plankton [
set energy (energy / 2)
hatch 1 [setxy random-xcor random-ycor]
]
if count plankton < 10 [
create-plankton 20
setxy random-xcor random-ycor
]
error: you can't use create-plankton in a turtle context, because create-plankton is observer only
I think I may understand the question.
to to have a turtle create turtles use HATCH. Your code would work (if I understand it) if you used
hatch-plankton 20
instead of
create-plankton 20
Did I get it right? Turtles hatch , patches spawn and observer creates.
the turtles hatched will be identical to the hatching turtles and will all be in a lump where hatch was called. Assuming that you do not want that.
use
hatch-plankton 20 [setxy random-xcor random-ycor]
I have incorporated this in the code, but when the count of plankton is zero, there will be no plankton respawned, this is because all plankton is dead and cannot be hatched. Do you know another way to spawn plankton or respawn turtles in general during a simulation even if they die?
Beneath the code to reproduce plankton:
to plankton-reproduce
while [count plankton != 0 and count plankton < 3000]
[ if random-float 100 < reproduce-plankton
[set energy (energy / 2)
hatch-plankton 1 [setxy random-xcor random-ycor]]]
if count plankton = 0
[set energy 1
hatch-plankton 20 [setxy random-xcor random-ycor]]
end

Move turtles around a patch

I am trying to move turtle around patch 0 0 starting from random position in world. But circle keeps on growing. What am I doing wrong here?.
Code:
to setup
clear-all
create-turtles 5
ask turtles [
setxy random-xcor random-ycor
]
ask patch 0 0 [ set pcolor green ]
reset-ticks
end
to go
move-turtles
tick
end
to move-turtles
ask turtles
[
face patch 0 0
right 90
fd 0.01
set pen-size 3
pen-down
]
end
Secondly I want a turtle to move around any patch I define when it reaches with in a certain range
Your approach is to take a small step along a tangent to the circle you want, but this takes you a little bit outside the circle. You do this repeatedly, so it accumulates over time.
For a better way, see the Turtles Circling example in the NetLogo Models Library.