Fish shoals

Fish shoals preview image

1 collaborator

Nicola_lettieri Nicola Lettieri (Author)

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 259 times • Downloaded 26 times • Run 0 times
Download the 'Fish shoals' 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

turtles-own [enemies friends nearest_friend speed escape escapeangle alert imitation dist dist2]
globals [step]

to setup
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  __clear-all-and-reset-ticks
  ask patches [set pcolor 101 + random-normal 0 0.1]
   cro predators_num [setxy random-xcor random-ycor set color red set shape "mare" set size 2.3 set speed random-float 0.5 ]
  cro fish_num
  [setxy random-xcor random-ycor
   set shape "mare"
   set color gray
   set size 1.3
   set speed random-float fish_speed
   set dist distance turtle 0
   set dist2 precision dist 3
   ;set label dist2
   set escape 0.3
   set escapeangle random-float 50
   set imitation (speed + escape) - speed]
set step random 1 + 3
end 

to go
choose_step
ask turtles [if speed < 0.1 [set speed 0]]
repeat step [ask turtles [fd speed] display]
ask turtles with [size = 1.3] [set color gray set speed random-float fish_speed set escape 0.3 set dist distance turtle 0
   set dist2 precision dist 3]
plotagents
end 

to choose_step
ask turtles with [size = 1.3]; chiedo alle turtle grigie
    [find_enemies ; trovate nemici
     ifelse any? enemies ; SE CI SONO NEMICI
        [set heading heading + 70 set speed speed + escape set color white] ; impostate in base a questi parametri l'orientamento ed il passo
        [find_friends ; SE NON CI SONO NEMICI... TROVA AMICI
        ifelse any? friends ; SE CI SONO AMICI...
           [find_nearest_friend  ; trova l'amico pi� vicino
            let heada [heading] of nearest_friend ; leggi il suo orientamento
            let speeda [speed] of nearest_friend ; leggi la sua velocita
            let colora [color] of nearest_friend
            set imitation (fish_speed + escape) - speeda
            ifelse eastwest?
                 [set heading heada + random-float (fish_speed + escape) - speeda ]
                 [set heading heada - random-float (fish_speed + escape) - speeda ]
            set color colora
           ]
                                                      ; ALTRIMENTI, SE NON CI SONO AMICI
          [ifelse eastwest?
          [set heading heading + random-float 15 ]
          [set heading heading - random-float 15]]
          ]
        ]

ask turtles with [color = red] ; chiedo alle turtle rosse
[set heading heading + random-normal 0 20 set speed random-float 0.3]
end 

to-report eastwest?  ; restituisce vero/falso in base al parametro [p] che viene "passato" nella procedura che richiama "to-report probability-fn?
  ifelse (random-float 100) < 50 ; se un numero a caso tra 0 e 1 � minore di p allora restituisci vero, altrimenti restitutisci falso
    [report true];
    [report false]
end 

to find_enemies
 set enemies other turtles in-cone visual_depth visual_angle with [color = red]
end 

to find_friends
 set friends other turtles in-cone visual_depth 180 with [color = gray]
end 

to find_nearest_friend;; turtle procedure
  set nearest_friend min-one-of friends [distance myself]
end 

to plotagents
set-current-plot "mean distance graph"
  set-current-plot-pen "Meandist"
    plot (mean [dist2] of turtles)
end 

There is only one version of this model, created about 9 years ago by Nicola Lettieri.

Attached files

File Type Description Last updated
Fish shoals.png preview Preview for 'Fish shoals' about 9 years ago, by Nicola Lettieri Download

This model does not have any ancestors.

This model does not have any descendants.