Change color based on pcolor - NetLogo - colors

I am trying to create a function in NetLogo that will allow me to use clickable "color swatches" to determine the color of a turtle. Here is my code so far:
if mouse-down?
[ ask patch mouse-xcor mouse-ycor
[ if pcolor != 0 mod 10
[ show pcolor
ask turtle whichturtle
[ set color pcolor]
]
]
]
(I have created a drop-down with the global variable which allows the user to select which turtle they would like to change.)
However, when I run this code, the specified turtle changes its color to the color of the patch it's currently standing on, rather than that of the patch the user clicked on.
How would I fix this problem? Any help is much appreciated.

You need to use myself to refer the patch that's asking the turtle to change its color:
ask turtle whichturtle [
set color [pcolor] of myself
]
It can get confusing, sometimes: learning to keep track of the context that you are doing things in is an important part of mastering NetLogo...
One way to avoid getting lost in the different levels of asking is to assign things to local variables at a place in the code execution where you know exactly where you are. In your case, it could have been something like:
if mouse-down? [
ask patch mouse-xcor mouse-ycor [
if pcolor != 0 mod 10 [
let chosen-color pcolor
ask turtle whichturtle [
set color chosen-color
]
]
]
]

Related

Can you have custom #info colors?

In Julia, I have a project where I have many calculations. Next is a tiny extract of what it could look like:
[ Info: Benders Solving with subtour constraints --- ./Instances/tiny_instance_10.txt ---
[ Info: Spent 0.039s in Benders decomposition
[ Info: Spent 0.035s in Master problem
[ Info: Spent 0.004s in subproblem
Objective : 47.80267061445823
[ Info: 4 Optimality Constraints created
[ Info: 4 Subtour Constraints created
[ Info: MILP Creating Model --- ./Instances/tiny_instance_10.txt ---
I mainly use #info to output data on console. [ Info: is in teal color, which is great and I would like to know if there exists a convenient way to get other colors? That would be better to read given I have many lines with #info to print.
Something like: #info red "MyString"?
I could not find in the Julia documentation.
I believe if it is not easily makeable with #info, I will have to create my own print function?
You could write it yourself
macro myinfo(color, what)
quote
printstyled($what,color=$color)
end
end
And now:

How to print a turtle variable equivalent to item 0 in a list in Netlogo?

I am trying to export a turtle variable value that is <= item 0 of a patch list. These are the values I am interested in recording, but I am having trouble getting the code right for that.
I've tried below:
file-print turtles with [turtlevariable <= item 0 patchlist]
I know that's not right as I am getting the number of turtles, and not the turtle variable value. I would like to run this model 1000 times and am unsure how to create code for a file that will be manageable to manipulate in Excel.
I'm pretty sure there is a simple answer, but I just can't figure it out! Any help is greatly appreciated.
You have multiple questions here. You need to post each question separately. I will take on the following: how can you get a list of values for turtlevariable, but only for the values that are < item 0 patchlist.
globals [patchlist]
turtles-own [tvar]
patches-own [pvar]
to test
ca
ask patches [set pvar random-float 1.0]
set patchlist [pvar] of patches
let _p00 item 0 patchlist ;;compute only once
crt 100
ask turtles [set tvar random-float 1.0]
let _tset (turtles with [tvar < _p00])
let _tvals [tvar] of _tset
print _tvals
end
You can always file-print anything you can print, so now you need to decide how exactly you want to format this list. This is a separate question. If you want to save as .csv, that is a separate question. (But you will find multiple questions on this site addressing that.) If you want to create one output file for multiple replicates, that is a separate question. (But see questions on this site about BehaviorSpace.) Hth.

Foilum map module, trying to get more options for marker colors

I am playing with Folium a lot right now and its really great to have something so easy to use in Python. But their documentation is seriously behind, which I understand. So I have 2 questions.
What am I doing wrong in how I am trying to get more marker colors? Here is what I have tried:
map.simple_marker(each_coord, popup=v[0], marker_color='#FFFF00')
map.simple_marker(each_coord, popup=v[0], marker_color='yellow')
map.simple_marker(each_coord, popup=v[0], marker_color='Yellow')
They should all make the marker yellow, instead it stays default red. The only colors I can actually change to are red, green, and purple. In an example from the folium documentation it looks like we should be able to use html color codes:
folium.CircleMarker([45.5215, -122.6261],
radius=500,
popup='Laurelhurst Park',
color='#3186cc',
fill_color='#3186cc',
).add_to(map_2)
But it doesn't work for me. Hope someone knows a way around this because I need at least 12 different colors for my project.
The way I am adding markers seems to be deprecated. It works, but I always get this warning: FutureWarning: simple_marker is deprecated. Use add_children(Marker) instead which I think might be related to why I can't get the colors to work. But their is nothing in any of the documentation or open discussions about how to use add_children Maybe someone with knowledge can clarify?
Thanks
I had the same problem. Here are the colors that work for markers:
colors = [
'red',
'blue',
'gray',
'darkred',
'lightred',
'orange',
'beige',
'green',
'darkgreen',
'lightgreen',
'darkblue',
'lightblue',
'purple',
'darkpurple',
'pink',
'cadetblue',
'lightgray',
'black'
]
folium.Marker([lat, lon], popup=str(name)+': '+color+'-'+str(clname), icon=folium.Icon(color=color)).add_to(feature_group)
In Icon,parameter color is limited, but icon_color can use RBG. Like:
folium.Marker([lat, lon], popup=str(name)+': '+color+'-'+str(clname), icon=folium.Icon(color='black',icon_color='#FFFF00')).add_to(feature_group)

Sound plays for half a second then stops?

When I play the sound file by itself (in interface) it works fine and plays all the way through. However, when I play it as part of the code (followed by an action) it only plays the first half second. I'm using sound:play-sound-and-wait, so I'm not sure why it isn't working.
extensions [sound] ; I have them in the same folder
to-report mouse-up?
ifelse mouse-down?
[report "false"]
[report "true"]
end
to twirl
if mouse-up?
[ask turtles with [shape = ballerina]
[set shape ballerina-2
twirl]
ask turtles with [shape = ballerina-2]
[set shape ballerina
twirl] ]
end
These are 2 different ballerina's facing different directions. When you switch between them, they look like they're twirling. She keeps doing that until you make her stop
to ballet-box
ask patches [set plabel-color 105] ;gives the background this color
sound:play-sound-and-wait "love.aif" ;this works perfectly fine in interface
twirl ;and then I want the ballerina to twirl until you make her stop
end
Any help would be super appreciated!
Sounds like http://github.com/NetLogo/Sound-Extension/issues/2 or http://github.com/NetLogo/Sound-Extension/issues/3 . I don't think anyone has yet investigated or attempted to fix these issues. I don't think we even know under exactly what circumstances they do or don't occur.

What code language is this?

I know, silly question, but I am not a programmer and really need to known...
to look-for-food
if food > 0
[ set color orange + 1
set food food - 1
rt 180
stop ]
if (chemical >= 0.05) and (chemical < 2)
[ uphill-chemical ]
end
Thanks
This language is called LOGO. It's often used with Turtle -- drawing lines on the screen.
Related Anecdote:
My first encounter with a computer was around 1985, in my classroom we had an Apple (Apple ][ probably?). This was one of the main programs that was available. I had learned how to do to in order to define a subroutine. I tried it once, but I couldn't remember the syntax for defining the specifics. And then when I tried to exit the to routine definition context, I couldn't remember how to exit it. The teacher could sense that I was confused, and was coming over to help me. I figured I'd be in trouble for straying beyond the scope of the exercise that I was supposed to be working on, and figured the teacher wouldn't know how to recover either. I panicked and powered off the computer. My first "did you try turning it off and on again?" experience! :)

Resources