MIHS LG LZ 5
No preview image
Model was written in NetLogo 3D 5.2.1
•
Viewed 96 times
•
Downloaded 11 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Lindsey Gao, Leo Zhang
Period 5
Note: We used an unfinished model of birds flocking in 2 dimensions and added a z coordinate to make the birds flock in 3 dimensions. This allows the birds to move up and down in the z axis. This model must be viewed in netlogo 3D.
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
turtles-own [ flockmates ;; agentset of nearby turtles nearest-neighbor ;; closest one of our flockmates ] globals [ scale ] to setup clear-all set scale 0.25 ;; scale let's us have a bigger world without too many patches create-turtles population [ set color yellow - 2 + random 7 ;; random shades look nice setxyz random-xcor random-ycor random-zcor right random-float 360 tilt-up asin (1.0 - random-float 2.0) roll-right random-float 360 set flockmates no-turtles ] ask turtle 0 [ set color red ] reset-ticks end to go ask turtles [ flock ] repeat 5 [ ask turtles [ fd scale / 2 ] display ] tick end to flock ;; turtle procedure find-flockmates if any? flockmates [ find-nearest-neighbor ifelse distance nearest-neighbor < ( minimum-separation * scale ) [ separate ] [ align cohere ] ] end to find-flockmates ;; turtle procedure set flockmates other turtles in-radius (vision * scale) end to find-nearest-neighbor ;; turtle procedure set nearest-neighbor min-one-of flockmates [distance myself] end ;;; SEPARATE to separate ;; turtle procedure turn-away ([heading] of nearest-neighbor) max-separate-turn pitch-away ([pitch] of nearest-neighbor) max-separate-turn end ;;; ALIGN to align ;; turtle procedure turn-towards average-flockmate-heading max-align-turn pitch-towards average-flockmate-pitch max-align-turn end to-report average-flockmate-heading ;; turtle procedure ;; We can't just average the heading variables here. ;; For example, the average of 1 and 359 should be 0, ;; not 180. So we have to use trigonometry. report atan sum [sin heading] of flockmates sum [cos heading] of flockmates end to-report average-flockmate-pitch ;; turtle procedure ;; We can't just average the heading variables here. ;; For example, the average of 1 and 359 should be 0, ;; not 180. So we have to use trigonometry. report atan sum [sin pitch] of flockmates sum [cos pitch] of flockmates end ;;; COHERE to cohere ;; turtle procedure turn-towards average-heading-towards-flockmates max-cohere-turn pitch-towards average-pitch-towards-flockmates max-cohere-turn end to-report average-heading-towards-flockmates ;; turtle procedure ;; "towards myself" gives us the heading from the other turtle ;; to me, but we want the heading from me to the other turtle, ;; so we add 180 report atan mean [sin (towards myself + 180)] of flockmates mean [cos (towards myself + 180)] of flockmates end to-report average-pitch-towards-flockmates ;; turtle procedure report mean [0 - (towards-pitch myself)] of flockmates end ;;; HELPER PROCEDURES to turn-towards [new-heading max-turn] ;; turtle procedure turn-at-most (subtract-headings new-heading heading) ( max-turn * scale ) end to turn-away [new-heading max-turn] ;; turtle procedure turn-at-most (subtract-headings heading new-heading) ( max-turn * scale ) end to pitch-towards [new-pitch max-turn] ;; turtle procedure pitch-at-most (subtract-headings new-pitch pitch) ( max-turn * scale ) end to pitch-away [new-pitch max-turn] ;; turtle procedure pitch-at-most (subtract-headings pitch new-pitch) ( max-turn * scale ) end ;; turn right by "turn" degrees (or left if "turn" is negative), ;; but never turn more than "max-turn" degrees to turn-at-most [turn max-turn] ;; turtle procedure ifelse abs turn > max-turn [ ifelse turn > 0 [ rt max-turn ] [ lt max-turn ] ] [ rt turn ] end to pitch-at-most [turn max-turn] ;; turtle procedure ifelse abs turn > max-turn [ ifelse turn > 0 [ tilt-up max-turn ] [ tilt-down max-turn ] ] [ tilt-up turn ] end
There is only one version of this model, created over 7 years ago by Lindsey Gao.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.