首页 > 其他 > 详细

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

时间:2014-01-21 23:05:03      阅读:342      评论:0      收藏:0      [点我收藏+]

生成自己的模型

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


bubuko.com,布布扣

bubuko.com,布布扣

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

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/


bubuko.com,布布扣

最后为瓦片加上色彩,黑色太单调,在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


bubuko.com,布布扣


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

原文:http://blog.csdn.net/myhaspl/article/details/18615149

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!