如何让乌龟以特定的颜色吸引?

时间:2015-08-05 15:02:43

标签: simulation netlogo modeling

我正在玩Netlogo,我为两个不同的群体分配了至少两种颜色。这两组代表两种不同的刻板印象 - 由蓝色和红色代表。

我的目标是: 我需要一个' RED'与所有其他红色一起聚集,蓝色与所有其他蓝色一起涌动。

这是我目前的代码。

breed [ firstgroups firstgroup ]
breed [ secondgroups secondgroup ]

turtles-own[
  groupmates 
  nearest-neighbor
]

to setup
  clear-all
  crt population-blue
  [ set size 1.5
    set shape "person"
    setxy random-xcor random-ycor 
    set color blue
   ]
  crt population-green
  [ set size 1.5
    set shape "person"
    setxy random-xcor random-ycor 
    set color green
   ]
  reset-ticks
end

to go
  ;;ask turtles [ group ]
  ask turtles [ fd 1 ]
  tick
end

;;to group
;;  ifelse (

1 个答案:

答案 0 :(得分:0)

turtles-own[
  groupmates ; unused
  nearest-neighbor
]

to setup
  clear-all
  setup-globals
  create-firstgroups population-blue ;use your breeds
  [ set size 1.5
    ;set shape "person"
    setxy random-xcor random-ycor 
    set color blue
   ]
  create-secondgroups population-green
  [ set size 1.5
    ;set shape "person"
    setxy random-xcor random-ycor 
    set color green
   ]
  reset-ticks
end

to go
  ask turtles [ group ] ;use `group`
  ask turtles [ fd 1 ]
  tick
end

to group ;turtle proc
  ;let _partner min-one-of other breed [distance myself] ;form subgroups
  let _partner one-of other breed ;form big gropus
  set heading mean-heading (list heading towards _partner)
end

to-report mean-heading [ headings ] ;by Bryan Head
  let mean-x mean map sin headings
  let mean-y mean map cos headings
  report atan mean-x mean-y
end