I am new to netlogo and was hoping if someone can help me with how to create turtles based on the user input.
In the interface tab i have a slider whose value ranges between 2 & 10. Depending on the value defined by the user using this slider, that many number of turtles should be created.
I tried using multiple if statements but there is a problem in the succeeding steps.
if (slider-value = 2) [create2]
if (slider-value = 3) [create3]
if (slider-value = 4) [create4]
if (slider-value = 5) [create5]
After creating the turtles using the above if conditions, i have to assign some rules to each individual turtle, and i tried again using multiple if statements. But it doesn't seem to work.
Can someone suggest a way, would really appreciate the help.
Thanks in advance!
Regards
You could more simply use the slider thus
create-turtles slider-value [
;things you want the turtles to do for example
set heading 4 * random 90
set shape "turtle"
set color green + random-normal 0 4
]
is this what you are looking for?
I recommend a switch statement.
A switch statement cycles through all your possible commands ,typically with an int. And then selects the match command.
So for example I could make a switch statement that when user inputs the up arrow. the int 1 is the input. this is matched to a command that tells the turtle to move up so many pixels/units/cubes.
I hope that helps.
Related
Im trying to change the maximum of a slider based on a Chooser. Something like
if confidence = "None" [set Maximum 1]
This is on the part of the slider that indicates the Maximum. However, i get the Expected Reporter Error, but i dont know how to do this right.
The best solution, in my opinion, is writing a reporter in your code tab and using that reporter to determine the maximum of your slider:
to-report slidermaximum
if confidence = "none" [report 1]
end
Another option is using ifelse-value, which allows you to return a reporter rather than a command. This one you can put directly into the slider menu.
ifelse-value confidence = "none" [1] [10]
I prefer the first one, since code hidden within your different submenus is easy to forget or overlook when you are making changes to the model later on.
I looked but could not locate any Netlogo code that links a set of sliders that, as one increases in value the other sliders decrease so the total value never exceeds 100% (even though the total can be less than 100%). Has anyone ever tried this?
Thanks
Rudy
You could implement it with something like an 'Update sliders' button, where you set the values you want for all the variables, then press the button and that calls a procedure to adjust them all so they add to no more than 100%. But sliders adjust either because the user adjusts them, or the NetLogo code says something like set variable-name new-value and that code is called in some way.
In practice, if I have multiple sliders that I don't want the total to exceed something, then I have a line at the start of the go procedure that checks the total and stops with a message if it's too high.
I am just curious if it's possible to alter the location of the labels in NetLogo. For example in the image below the word "La Grande Soufriere", is it possible to move it above the breed instead of below (as you can see it gets in the way of the other agents. Another case is the Habitants PMA (Actual name is Vieux Habitants) but only half of its name has appeared since the rest of its off-screen. I tried to manually type on a close-by patch but since I have used a fill color, it doesn't appear at all (it's covered by the fill color if you know what I mean). Does anyone have a solution for this?
I am just curious if it's possible to alter the location of the labels in NetLogo.
The short answer is that it is not possible.
The slightly longer answer is that there are ways around it, but they're not very satisfying.
If you want to alter the horizontal location, you can pad your label with spaces at the end or the beginning of the string to move it left or right, respectively.
If you want to alter the vertical location, or have more control over it, you can always create a "dummy" turtle to display the label. You can hide the dummy turtle without hidding its label by setting the size of the turtle to zero or by creating an empty turtle shape and using that for it.
I don't think it matters in your case, since you seem to want to label only stationary turtles, but if you wanted a dummy to move with a particular turtle, you can create a hidden link between them and tie them.
There might be other creative ways to deal with labels (and I'd be curious to read about them in other answers), but that's all I can think of for now.
I have been experimenting trying to work out how does the export-world work, in particular how does the DRAWING section work.
I created the following code to experiment using the default environment size of max-pxcor and max-pycor of 16. If you run this code shown at the end of this post, each file produced will be 5 megabytes, so it is easy to use up over a gigabyte of data after a minute of running.
Anyway, my question is this: How does the DRAWING section work? I have seen that the first entry is at -16.4, 16.4. I have summarised some of my observations in the simple table below. The first column is how much the turtle has moved, while the second column shows partial output in the CSV file.
0.001 FF1D9F78
0.016 FF1D9F78FF1D9F78
0.093 FF1D9F78FF1D9F78FF1D9F78
I have also seen that the first entry is created when the turtle moves by 0.001.The second entry seems to happen when the turtle has moved by 0.016 and the third entry is 0.093.
I am trying to work out what the pattern could be, but there doesn't seem to be one. How much turtle movement does one of the entries represent in the CSV file?
Thanks.
---- The code is below.
globals
[
totalAmount
]
to setup
ca
crt 1
[
setxy -16.4 16.4
pd
set heading 90
set color turquoise
]
set totalAmount 0
end
to go
ask turtles
[
fd moveAmount
]
set totalAmount moveAmount + totalAmount
export
end
to export
let filetemp word "turtletest" totalAmount
let filename word filetemp ".csv"
;print filename
export-world filename
end
The drawing layer is just a bitmap – a grid of pixels. It doesn't know what turtles moved and how far, it only knows what pixels the turtles colored in while moving. Internally, it's a java.awt.image.BufferedImage with TYPE_INT_ARGB encoding.
It's written to an exported world file by this code:
https://github.com/NetLogo/NetLogo/blob/533131ddb63da21ac35639e61d67601a3dae7aa2/src/main/org/nlogo/render/TrailDrawer.java#L217-L228
where colors is the array of ints backing the BufferedImage, and toHexString just writes bytes as hexadecimal digits (code).
If your image is mostly black, you'll mostly see a bunch of 00 bytes in the file.
As for your non-zero bytes, it appears to me that FF1D9F78 is a pixel with alpha = FF (opaque), red = 29, green = 159, blue = 120. At least, I think that's the right interpretation? Is that plausible for what you're seeing on screen? Maybe the A-R-G-B bytes are in the reverse order? To double check it, I'd need to do export-view and then look at the resulting PNG file in a program that could tell me the RGB values of individual pixels -- I don't have such a program handy right now. But hopefully this'll put you on the right track.
Let's say I have two sliders on my interface. Slider one goes from 0-500 and slider two goes from 0-100.
Is there anyway of setting it so that the value of slider one influences the possible values for slider two. So if I set slider one to 500, slider two can only be values from 0-30, for example.
Alternatively it would not necessarily have to be a slider affecting another slier, it could be a button. So if I have buttons A and B, if I select A the slider can be 0-10 but if I select B only 20-50.
Bit of a strange query I admit, I've just been tasked with making an interactive "model" for kids to try out different systems.
Thanks for taking the time to read this.
Yes, you can do this. Example: make 3 sliders: test0, test1, test2. Let the min and max values of test0 be test1 and test2. Let the min and max values of test1 be 0 and 5, and set a value of 1. Let the min and max values of test2 be 95 and 100, and set a value of 99. Your test0 slider will now work as hoped.
BUT what happens if you make the min and max values of test0 to test2 and test1? OK, you get odd behavior, which is likely to look broken to your "kids". So ... this arrangement is not a good one. If you describe your goals in more details, maybe we can find a better solution.