Reputation: 21
I want some of my turtles to leave at trace of the steps they make. I want them to change the color of the patches they pass by on their move. Similar to what the "pen-down" command does - just with the effect, that the patches change color. It is esay for me to change the color of the patch, the turtle reach - but I want all the patches colored - like if you were walking on a lawn, and the grass under you momentaneouesly turns red :-) Nut just the steps with every tick, but the continous route. Is there a way? I would be glad to se a small coded example. Thanks very much - this homepage does a great job. Magellancruiser
Upvotes: 0
Views: 277
Reputation: 2780
Here is one basic solution. The key is realizing that instead of having the turtle do something like forward (random 10) + 1
you can instead have it go forward 1
a number of times equal to (random 10) + 1
. Because the distances are based on path sizes (1 = 1 patch across), if you color the patches as you go forward 1
at a time, you should "draw" the color on the patch.
turtles-own [ my-color ]
to setup
clear-all
create-turtles 10 [
set my-color color ; the turtles will have random colors, store them to use later
set color white ; but they're easier to see if they're white
]
reset-ticks
end
to go
ask one-of turtles [
left (random 50) - 25 ; wiggle a bit to not just go in a straight line
let d (random 10) + 1 ; the turtle will move 1 to 10 steps
repeat d [
forward 1
set pcolor my-color ; the turtle can directly set the patch's pcolor variable to its own
]
]
tick
end
You can either use setup
and go
from the command center or add buttons for them.
Upvotes: 1