数学之路-群体行为与群体智能(4)

来源:互联网 发布:社交网络头像 编辑:程序博客网 时间:2024/05/20 19:19

生成自己的模型

选择文件->新建,增加模型后,选择增加,增加初始化和运行2个按钮,如下图所示:



然后选择程序->编写代码:

to setup

  clear-all

  create-turtles 100

  ask turtles[setxy random-xcor random-ycor]

end

to go

  move-turtles

end

to move-turtles

  ask turtles[

    right random 360

    forward 1

  ]

End

然后运行一下程序,先初始化,然后点击运行,可看到不同色彩的三角形按随机的方向移动:

麦好的AI乐园博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/



最后为瓦片加上色彩,黑色太单调,在setup中增加一个setup-patches的例程,全部代码如下:

to setup

  clear-all

  create-turtles 100

  ask turtles[setxy random-xcor random-ycor]

  setup-patches

end

to go

  move-turtles

end

to move-turtles

  ask turtles[

    right random 360

    forward 1

  ]

end

to setup-patches

  ask patches[set pcolor blue]

end




0 0
原创粉丝点击