MIHS Bella and Mathi Period 3

No preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.1 • Viewed 103 times • Downloaded 12 times • Run 0 times
Download the 'MIHS Bella and Mathi Period 3' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [fishes fish]

turtles-own [
  flockmates            ;; agentset of nearby turtles
  nearest-neighbor      ;; closest one of our flockmates
]

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end 

to go
  move-turtles
  ask turtles [ flock ]
;; the following line is used to make the turtles
;;animate more smoothyly.
repeat 5 [ ask turtles [ fd 0.2 ] display ]
;; for greater efficiency, at the expense of smooth
;; animation, substitue the following line instead:
;; ask turtles [ fd 1 ]
  tick
end 

to flock ;; turtle procedure
  find-flockmates
  if any? flockmates
  [ find-nearest-neighbor
    ifelse distance nearest-neighbor < minimum-separation
    align
    cohere ]
end 

to find-flockmates ;; turtle procedure
  set flockmates other turtles in-radius vision
end 

to find-nearest-neighbor ;; turtle procedure
  set nearest-neighbor min-one-of flockmates [distance myself]
end 

;;; ALIGN

to align ;; turtle procedure
  turn-towards averafeflockmate-heading 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 hae to use trigomentary
  let x-component sum[dx] of flockmates
  let y-component sum [dy] of flockmates
  ifelse x-component = 0 and y-component = 0
  [ report heading ]
  [ report atna x-comonent y-component ]
end 

;;; COHERE

to cohere ;; turtle procedure
  turn-towards average-heading-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
  let x-component mean [sin (towards myself + 180)] of flockmates
let y-component mean [cos (towards myself + 180)] of flockmates
lifelse x-component = 0 and y-compnent = 0
[ report heading ]
[ report atan x-component y-component ]
end 

;;; HELPER PROCEDURES

to turn-towards [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings new-heading heading) max-turn
end 

to turn-away [new-heading max-turn]  ;; turtle procedure
  turn-at-most (subtract-headings heading new-heading) max-turn
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 move-turtles
  ask turtles [
    right random 45
    forward .5
  ]
end 

to setup-patches
  ask patches [ set pcolor 85 ]
end 

to setup-turtles
  create-turtles 50
  ask turtles [set shape "fish" ]
  ask turtles [ set color 25 ]
  ask turtles [ setxy random-xcor random-ycor ]
end 

There is only one version of this model, created over 7 years ago by Mathi Ngamsiripol.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.