如何设置滑块制作的海龟的颜色?
How to set color of turtles made by slider?
我正在尝试创建一个模拟,其中有僵尸和人类乌龟在世界各地移动。我正在使用 2 个滑块来创建不同数量的僵尸和人类。我想将僵尸的颜色设置为绿色,将人类设置为红色。到目前为止,这是我的代码:
to setup
cro Zombies
cro Humans
ask turtles [set shape "person"]
end
我不确定如何设置僵尸和人类的颜色,因为它们仅被解释为数字,我无法使用:
ask Zombies [set color green]
任何想法都非常感谢!
您有什么理由不想使用 breed
吗?从长远来看,这可能会让你的生活变得更轻松 运行。例如,这个基本设置有两个像您一样的滑块,但请注意它们被称为 "n-Zombies" 和 "n-Humans":
breed [ zombies zombie ]
breed [ humans human ]
to setup
ca
set-default-shape turtles "person"
; create a number of zombies set by the "n-Zombies" slider
create-zombies n-Zombies [
set color green
setxy random-xcor random-ycor
]
; create a number of humans set by the "n-Humans" slider
create-humans n-Humans [
set color red
setxy random-xcor random-ycor
]
reset-ticks
end
给你这样的东西:
我正在尝试创建一个模拟,其中有僵尸和人类乌龟在世界各地移动。我正在使用 2 个滑块来创建不同数量的僵尸和人类。我想将僵尸的颜色设置为绿色,将人类设置为红色。到目前为止,这是我的代码:
to setup
cro Zombies
cro Humans
ask turtles [set shape "person"]
end
我不确定如何设置僵尸和人类的颜色,因为它们仅被解释为数字,我无法使用:
ask Zombies [set color green]
任何想法都非常感谢!
您有什么理由不想使用 breed
吗?从长远来看,这可能会让你的生活变得更轻松 运行。例如,这个基本设置有两个像您一样的滑块,但请注意它们被称为 "n-Zombies" 和 "n-Humans":
breed [ zombies zombie ]
breed [ humans human ]
to setup
ca
set-default-shape turtles "person"
; create a number of zombies set by the "n-Zombies" slider
create-zombies n-Zombies [
set color green
setxy random-xcor random-ycor
]
; create a number of humans set by the "n-Humans" slider
create-humans n-Humans [
set color red
setxy random-xcor random-ycor
]
reset-ticks
end
给你这样的东西: