【问题标题】:How to create two different random color groups in NetLogo 6.1.1?如何在 NetLogo 6.1.1 中创建两个不同的随机颜色组?
【发布时间】:2020-02-24 19:29:01
【问题描述】:

如何在 NetLogo 6.1.1 中创建两个不同的随机颜色组?

我正在尝试从 250 只海龟中创建两个不同的组。开始的情况是250只乌龟都是灰色的,然后它们会依次变成黄色和粉红色的一组。

我的这段代码一开始所有的海龟都是灰色的,然后它们都会变成粉红色。我不想要这个,但我想要两个随机制作的组,在代码运行结束时,粉色海龟通常比黄色海龟组更大或更小。

我刚开始使用 NetLogo 6.1.1 进行编码。感谢您的理解和所有帮助,祝您有愉快的一天。

[
  time

  person
]


turtles-own [ x ]

to setup

  clear-all
  reset-ticks
  set time  0
  create-turtles 250 

  [
      setxy random-xcor random-ycor 

  ]  

  ask turtles

  [
    set shape "person"
    set size 1
    set color gray
  ]

  end


to go 

  ask turtles


 [

    show random 2 = x

    if x = 1 [set color yellow] 
    if x = 0 [set color pink]
  ]


end ```

【问题讨论】:

    标签: random colors netlogo


    【解决方案1】:

    我没有看到任何地方设置了海龟变量x 的值,因此它们将始终具有0 的默认值。在 NetLogo 中,= 用于检查相等性,而不是用于赋值,因此 show random 2 = x 将打印 truefalse,具体取决于 random 2 是否为 0(如果您认为这是赋值) .你会想要这样的东西:

    to go 
      ask turtles
      [
        set x random 2
        if x = 1 [set color yellow] 
        if x = 0 [set color pink]
      ]
    end
    

    如果您只想设置一次值以便稍后在go 中使用,您可以将set x random 2 移动到setup 过程。

    【讨论】:

    • 您可以通过接受 Jasper 的回答(使用旁边的大勾号)来换取 Jasper 的快乐。
    猜你喜欢
    • 1970-01-01
    • 2017-02-20
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2021-04-14
    • 2015-04-26
    • 1970-01-01
    相关资源
    最近更新 更多