Reputation: 79
I am reusing the Traffic 2 Lanes sample on Netlogo to try and simulate how a smart self driving car operates around regular cars. There are 5 different levels of autonomy from Level 1-5. I have a slider for this called level-of-autonomy, but all it does now is just change all the colours of the cars that have a greater level of autonomy to red, I'll post it below. How do I make the colour of like half the cars on the road, when the user uses the slider to determine the amount of cars in total when I set the level of autonomy to lets say 4 so the cars are like lets say blue, then level 5 cars like yellow for example.
So lets say the slider for the amount of cars is like set on 40, I would like 20 cars to be a specific colour for the 5 different levels, how can this be done, any help would be wonderful, especially from the user Charles.
Upvotes: 2
Views: 614
Reputation: 541
ask turtles
already selects the turtles one by one randomly. so to randomly assign a color to half of an agentset, it is enough to simply count the number of colored agents and stop coloring when the target amount is reached.
ask turtles [
if [count turtles with [color = blue] < number-of-cars / 2][
set color blue
]
]
Upvotes: 3