I want to delete only turtle pen lines from a halfway point in a model run. The "clear-drawing" primitive seems to achieve that, but my problem is that I can't run it directly from an agent, or use "ask observer [clear-drawing]". Is there a way to trigger this observer command from an agent context (I expect not), or is there another way of erasing turtle pen lines? My solution to re-draw using pens having the background color is rubbish.
Instead of redrawing using the background color, use pen-erase. If that's equally “rubbish”, perhaps you want something more like the answers here? NetLogo turtles leaving a trail that fades with time
About clear-drawing being observer-only though, that seems like it shouldn't be too hard to work around, something like:
to go
let clear? false
ask turtles [
...
if ... [
set clear? true
]
...
]
if clear? [ clear-drawing ]
tick
end
Related
I am trying to build a model in which turtles decide to change colour depending on their environment in a network.
The approach would be to "check" the colour of the surrounding turtles and then set an if statement for the turtle in question to switch colour (there will only be 2 colours).
Specifically I would like to know how can a turtle "see" or check other turtles' colour (or other properties).
If possible I would also like to create a slider for "how many links away" can turtles see their neighbouring turtles' (or neighbours of neighbours, etc) colour.
I am new to both Netlogo and Stackoverflow, so please let me know if I should make any modifications to my model and/or question.
Thanks!
Welcome to Stack Overflow! Typically you'll want to stick to a single question per post, both for simplicity and for the benefit of future users with similar questions. As well, in cases where its applicable you should try to include some code to show what you've tried so far, as well as any setup necessary- you want to make a minimal, complete, and verifiable example. In this case, I think you're okay since your questions are clear and well explained, but if you have more complex questions in the future you will be more likely to get useful answers by following those guidelines.
For your first question, it looks like you want the of primitive- check out the dictionary entry for details. of can be used in a few ways, including allowing agents to check the value of a variable (such as color) of another agent. Check out this example code:
to setup
ca
reset-ticks
crt 10 [
setxy random 30 - 15 random 30 - 15
create-link-with one-of other turtles
]
end
to go
ask turtles [
set color [color] of one-of link-neighbors
]
end
Every time the go procedure is called, one of the turtles changes its color to the color of one of its link-neighbors. If you run it long enough, all connected turtles should end up with the same color.
For your second question, I suggest you check out the Nw extension, which is an extension built to deal more easily with Netlogo networks. Specifically, have a look at nw:turtles-in-radius, which should work with your slider approach. To get it working, include the extension using
extensions [ nw ]
at the start of your code. Then, assuming the same setup as above, you can play around with something like
to network-radius
ask one-of turtles [
set color red
ask other nw:turtles-in-radius 2 [
set color white
]
]
end
When you call the network-radius procedure above, you should see one turtle turn red, and any turtles within 2 links of that turtle turn white. To switch to a slider, just swap the "2" out for your slider variable. Hope that helps!
I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.
I am 'watch'-ing an agent and now want to programmatically 'unwatch' the agent (so that no agents are being watched).I am running the model using the 3D view (in NetLogo 5.0.4). It seems from the User Manual that the only way of unwatching is to use 'reset-perspective', but this has the undesirable side effect of resetting the perspective in the 3D view. Is there a better way of unwatching that does not disturb the view?
As far as I know, there is no way to call reset-perspective in NetLogo 3D without returning the observer to its default position.
There is, however, a way to work around this: you can ask the subject currently being watched to hatch a hidden "dummy" turtle at its current position and watch this dummy instead while your original subject keeps on moving. (It's not seamless, though, because the "spotlight" circle stays around the dummy.)
Here is a full example, in which there is a travelers breed for the regular turtles and a cameras breed for the dummies:
breed [ travelers traveler ]
breed [ cameras camera ]
to setup
clear-all
create-travellers 10
watch one-of travelers
end
to go
ask travelers [ fd 0.1 ]
end
to stop-watching
if subject != nobody [
ask subject [
hatch-cameras 1 [
set hidden? true
watch-me
ask other cameras [ die ]
]
]
]
end
This assumes that stop-watching is called from an interface button.
Support for programmatic control of the observer in NetLogo 3D is... spotty.
You could store the values of __oxcor, __oycor, and __ozcor and then restore them using setxyz after calling reset-perspective.
But there's also pitch and roll. You can read them with __opitch and __oroll, but it appears to me they are not directly settable. I imagine you could use facexyz to restore the pitch at least, but not the roll? 3D stuff confuses me.
Note that NetLogo's extensions API could be used to write an extension that does what you want.
I need to learn concurrently when a turtle changes its heading. Namely, when the turtle changes its direction, a procedure or a reporter will change the value of a boolean. But this reporter won't be called by any other procedures, it will be always running (checking turtle's heading) while the turtle is moving. Is there any way of this in NetLogo?
I think you can achieve something similar to what you want with a "forever" button: that is, a button that runs a procedure constantly. (People usually have at least one button like that, typically named "go", in their models.)
Assuming the heading you want to track is that of turtle 0, you can have code like this:
globals [
current-heading
heading-has-changed
]
to check-heading-changes
if [ heading ] of turtle 0 != current-heading [
set heading-has-changed true
set current-heading [ heading ] of turtle 0
]
end
To have the check-heading-changes code run constantly, you just need to call it from a "forever" button:
You have to remember to click the forever button when you want to start the monitoring. Now, of course, the code above also assumes that you will have some other procedures running that controls the turtle, and also that will actually do something (and reset the variable) when heading-has-changed becomes true.
I am using an existing model in netlogo called Chemical Equilibrium and am adding some more code. I want to add turtles (catalyst) which have no effect on the reaction/other turtles but speeds up the FORWARD reaction, which has been defined as follows:
to react-forward [t]
ask t [ set color red ]
set color green
rt random-float 360
jump 2
end
I was thinking that I should put a switch and a slider, make the turtles into whitemols or I do a turtles-own [catalyst] and then define that like I have done with temperature and pressure. I tried the following but it didnt work.
turtles-own [speed catalyst]
crt whitemols
[ set color white
randomize
set speed 1
]
I know the above code is incorrect but am not sure how to code this particular feature.
There are many ways to do this, of course. I can't tell what is going on in your program from the little snipped you include.
One way would be to have the catalyst be of a different breed:
breed [catalysts catalyst]
breed [chemical-x chemical-x]
;and so on
;then the forward reaction is sped up by the existence of catalysts
to react-forward
let num-catalysts count catalysts
;speed up by num-catalysts
;...
end