如何设置改变颜色后的默认颜色(进入模型时的颜色)?



我写了一行代码,就是这个

ask turtles [if count other turtles in-radius 1 > 5 [set color white]]

现在,当的颜色变为白色时,但是经过一定时间后,此属性对于同一只来说不成立,它应该将其颜色更改为默认颜色吗? 我该如何解决它?

我认为您追求的是一个turtles-own计数器,只要条件不满足,计数器就会减少。通过此设置:

turtles-own [ default-color countdown ]
to setup
ca
crt 150 [ 
setxy random-xcor random-ycor 
set default-color blue
set color default-color
]
reset-ticks
end

现在,您可以让您的海龟四处游荡,并在它们变色时更改它们的countdown变量。当不满足该条件时,他们可以减少计数器,直到它达到零,此时他们可以恢复到默认颜色。评论中的更多详细信息:

to go
ask turtles [
rt random 60 - 30
fd 0.25
; if there are more than 5 turtles in radius 3,
; turn white and set countdown to 5   
ifelse count other turtles in-radius 3 > 5 [
set color white 
set countdown 5
] [
; If not, and counter is greater than 0,
; decrease the counter. 
if countdown > 0 [
set countdown countdown - 1
; If counter gets down to 0, 
; set color back to the default.
if countdown = 0 [
set color default-color
]
]
]
]
tick
end

最新更新