SMS
Home
About
Hips & Heels
Research
CV
Personal Projects
Web Development
SMS
Home
About
Hips & Heels
Research
CV
Personal Projects
Web Development
More
  • Home
  • About
  • Hips & Heels
  • Research
  • CV
  • Personal Projects
  • Web Development

  • Home
  • About
  • Hips & Heels
  • Research
  • CV
  • Personal Projects
  • Web Development

NetLogo

;; Initialize the agent types

;; Note: the order in which breeds are initialized determines the way the output is layered. Must follow this order to put the bubbles on the 'bottom' and amoebas on 'top'.

breed [bubbles bubble]

breed [protists protist]

breed [amoebas amoeba]


globals [num_protists]




;; set up the simulation space

to setup

  clear-all


   create-bubbles 40 [

    setxy random-xcor random-pycor

    set size random-float 1.5

    set shape one-of ["circle"]

    let bluegreen (rgb 0 128 128)

    set color bluegreen

  ]


  set num_protists 30

  create-protists num_protists [

    setxy random-xcor random-ycor

    set shape "bacterium"

    set color orange

    set size 3

  ]


  create-amoebas 1 [

   setxy random-xcor random-ycor

   set size 7

   set shape "amoeba"

   set color magenta

  ]



  ask patches [

    let bluegreen (rgb 0 140 128)

    set pcolor bluegreen

  ]

  reset-ticks

end


;; run the simulation recursively

to go

  if count protists = 0 [stop] ;; stops the simulation if there are no protists

  if ticks = 500 [stop] ;; stops the simulation if ticks reach 500.

  move-bubbles

  protist_move

  amoeba_move

  tick

end

; Level-1 protist movement function. Use 'ctrl + ;' to uncomment blocks.

;

to protist_move

  ask protists [

    ifelse random-float 1.0 < 0.5 [rt random 360] [lt random 360]

    forward protist_step_size

  ]

end


;; Level-2 protist movement. Protists have an escape capability when the amoeba gets too close.

;to protist_move

;  ask protists [

;    let nearby_amoeba one-of amoebas in-radius protist_sensory_radius

;    ifelse nearby_amoeba != nobody [

;      ; Turn away from the nearby amoeba

;      face nearby_amoeba

;      ;rt random 180

;      ifelse random-float 1.0 < 0.5 [rt random 180] [lt random 180]

;      forward 2.5

;    ] [

;      ; Original random movement

;      ifelse random-float 1.0 < 0.5 [rt random 360] [lt random 360]

;      forward protist_step_size

;    ]

;  ]

;end


;; Level-1 amoeba movement function. No sensory capacity. ** Use ctrl-; to uncomment blocks

to amoeba_move

  ask amoebas [

    ifelse random-float 1.0 < 0.5 [rt random amoeba_max_angle fd amoeba_step_size ] [lt amoeba_max_angle fd amoeba_step_size]

    if any? protists in-radius 7 [

      let potential-eaten protists in-radius 1

      let eaten one-of potential-eaten

      if eaten != nobody [

        ask eaten [ die ]

      ]

    ]

  ]

end


; ;Level-2 amoeba movement function. Amoeba projects a 'sensory cone'. The amoeba will navigate toward protists that end up in its sensory cone.

; ;Protists change color to yellow when they are in the cone.

;to amoeba_move

;  let amoeba_view-radius 8 ; Define the radius for the field of view

;  let amoeba_view-angle 60 ; Define the angle for the field of view

;

;  ; First, reset the color of all protists to their original color

;  ask protists [

;    set color orange

;  ]

;

;  ask amoebas [

;    ; Find protists in the cone of vision

;    let protists-in-view protists in-cone amoeba_view-radius amoeba_view-angle

;

;    ; Change the color of the protists in the cone of vision to yellow

;    ask protists-in-view [

;      set color yellow

;    ]

;

;    ; Actual movement logic

;    if any? protists-in-view [ ; If there is any protist in view

;      let target one-of protists-in-view ; Pick one protist randomly as target

;      face target ; Turn towards the target

;      if can-move? amoeba_step_size [ ; Check if it's safe to move forward

;        forward amoeba_step_size

;      ]

;      if distance target <= 3 [ ; If close enough to eat

;        ask target [ die ] ; Eat the protist

;      ]

;    ]

;    if not any? protists-in-view [ ; If no protist in view, move randomly

;       ifelse random-float 1.0 < 0.5 [rt random amoeba_max_angle fd amoeba_step_size ] [lt amoeba_max_angle fd amoeba_step_size]

;    ]

;      ]

;end


;; Makes small bubbles in the background for aesthetic effect

to move-bubbles

  ask bubbles [

    set heading 0 ; 0 degrees is upwards

    forward random-float 0.25

    if ycor >= max-pycor [

      setxy random-xcor min-pycor ; reset to the bottom when a bubble reaches the top

    ]

  ]

end

Copyright © 2025 SMS - All Rights Reserved.

  • microbe mania install
  • SK Day Code

Powered by

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept