Light to Brain Model

Light to Brain Model preview image

2 collaborators

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.3.0 • Viewed 46 times • Downloaded 2 times • Run 0 times
Download the 'Light to Brain Model' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

; creating all variables used other than sliders that are present on interface
globals[
  StepSize ; how far photon moves with each tick
  rods-stimulated ; how many rods were stimulated by a burst of photons
  ystart ; starting y coordinate of yellow photons at the lefthand side of the screen
  ycell ; default y coordinate for retinal cells in zoomed in window
  yline ; starting y coordinate of green photons along white line
  cycles ; one cycle is one run of the simulation (i.e. one burst)
  number_photons ; the number of photons sent out per burst
  decays ; number of photons that have been absorbed in a cycle (gets updated continuously)
  CorneaDecay ; absorption value for cornea per pixel
  AqueousHumourDecay ; absorption value for aqueous humour per pixel
  VitreousHumourDecay ; absorption value for vitreous humour per pixel
  LensDecay ; absorption value for lens per pixel
  RetinaDecay ; absorption value for lens per pixel
  nwater ; absorption value for water per pixel with respect to depth
  irisMin ; magnitude of y coordinate of inside of iris (radius of pupil)
  bkgdcolor ; a number is assigned to represent a given background colour
  beamradius ; variable to convert beamwidth slider value (in mm) to pixels
  photoncount ; a list of the number of photons at each tick from 0 to 600
  currentphotons ; variable used to create blue line on the photon vs time graph
  ; it is the average of the number of photons at a given tick value over the cycles that have occurred
  gphotons ; the number of green photons that have appeared in the zoomed in retinal panel on the right side of interface
]

breed [photons photon] ; breed for turtles that act as photons to allow for easier
breed [bolts bolt] ; breed for turtles shaped like lightning bolts that represent the signal that is sent when enough rods are stimulated

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; setup procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; regular simulation setup procedure. must be activated after sliders are changed and before any other button

to setup
  clear-all
  ; set up standard background colour by filling entire interface with grey
  ask patches
  [
    if pxcor <= max-pxcor
    [
      set pcolor grey
    ]
  ]

  ; create white line to split interface
  ask patches with  [pxcor = 100]
  [
    set pcolor white
  ]

  ; the number of pixels a photon will move by on each tick
  set StepSize 1

  ; set variables/lists to 0 and will later be given values
  set bkgdcolor 0 ; variable to check background colour: 0 if grey, 1 if blue
  set cycles 0
  set gphotons 0
  set decays 0
  set rods-stimulated 0
  set photoncount (n-values 601 [0]) ; set up list to have 601 entries of zero so they can be identified and replaced later

  ; set decay/absorption rates to match literature values (references outlined in info tab)
  set CorneaDecay 0.0084929
  set AqueousHumourDecay 0.0013648
  set VitreousHumourDecay 0.00050404
  set LensDecay 0.0010123
  set RetinaDecay 0.001358
  set nwater 0.002

  ; call set scale procedure that creates the scale bars
  setscale

  ; call procedures that draw the parts of the eye
  ; size and distances are scaled version of actual eye layer dimensions
  sclera
  VitreousHumour
  aqueoushumour
  lens
  cornea
  irisStructure
  retina

  ; add labels for temporal and nasal sides of the eye
  ask patch (-60) (175) [set plabel-color 9.9 set plabel "Temporal"]
  ask patch (-60) (-175) [set plabel-color 9.9 set plabel "Nasal"]

  ; write "loading ..." in output on interface which will later announce if a visual response has occurred
  output-write "Loading ..."

  reset-ticks
  ; call procedure that makes photons so there are photons when the simulation starts
  make-photons
end 

; procedure to create scale bars

to setscale
  ; scale bar for left side of interface
  ; this scale was calculated to be 12 pixels/mm
  ask patches with [pxcor >= -290 and pxcor < (-290 + 120) and -180 >= pycor and pycor >= -190] [set pcolor 0] ; draw a 10 mm-long scale bar in the lower left corner
  ask patch (-215) (-170) [set plabel-color 0 set plabel "10 mm"]  ; add the label for the scale bar

  ; scale bar for right side of interface (zoomed in retinal window)
  ; this scale was calculated to be 1 pixels/μm
  ask patches with [pxcor >= 288 and pxcor < (298) and (-190 + 40) >= pycor and pycor >= -190] [set pcolor 0] ; draw a 40 μm-long scale bar in the lower right corner
  ask patch (298) (-130) [set plabel-color 0 set plabel "40"]  ; add the label for the scale bar
  ask patch (298) (-140) [set plabel-color 0 set plabel "μm"]
end 

; experimental setup procedure which is the same as standard setup but without calling "clear-all" first as that would clear all plot data on the interface

to setupexp
  ; the following clear procedures are still necessary to reset the interface and variables for each run
  clear-drawing
  clear-turtles

  ; set up standard background colour by filling entire interface with grey
  ask patches
  [
    if pxcor <= max-pxcor
    [
      set pcolor grey
    ]
  ]

  ; create white line to split interface
  ask patches with  [pxcor = 100]
  [
    set pcolor white
  ]

  ; the number of pixels a photon will move by on each tick
  set StepSize 1

  ; set variables/lists to 0 and will later be given values
  set bkgdcolor 0 ; variable to check background colour: 0 if grey, 1 if blue
  set cycles 0
  set gphotons 0
  set decays 0
  set rods-stimulated 0
  set photoncount (n-values 601 [0]) ; set up list to have 601 entries of zero so they can be identified and replaced later

  ; set decay/absorption rates to match literature values (references outlined in info tab)
  set CorneaDecay 0.0084929
  set AqueousHumourDecay 0.0013648
  set VitreousHumourDecay 0.00050404
  set LensDecay 0.0010123
  set RetinaDecay 0.001358
  set nwater 0.002

  ; call set scale procedure that creates the scale bars
  setscale

  ; call procedures that draw the parts of the eye. size and distances are scaled version of actual eye layer dimensions
  sclera
  VitreousHumour
  aqueoushumour
  lens
  cornea
  irisStructure
  retina

  ; add labels for temporal and nasal sides of the eye
  ask patch (-60) (175) [set plabel-color 9.9 set plabel "Temporal"]
  ask patch (-60) (-175) [set plabel-color 9.9 set plabel "Nasal"]

  ; write "loading ..." in output on interface which will later announce if a visual response has occurred
  output-write "Loading ..."

  reset-ticks
  ; call procedure that makes photons so there are photons when the simulation starts
  make-photons
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; draw eye layers & cells ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; procedure to draw cornea

to Cornea
  ; draw cornea by filling in the region between a circle and ellipse
  ; the outer circle has the same radius of curvature as the cornea
  ; the inner ellipse is placed at the literature distance from the outer layer
  ask patches with [(pxcor + 144) ^ 2 + (pycor) ^ 2 < 8761 and (pxcor + 140 ) ^ 2 + (pycor / 1.05) ^ 2 > 8661]
  [
    set pcolor pink
  ]
end 

; procedure to draw sclera

to Sclera
  ; fill in region between concentric circles
  ; circle size was determined so that the distance between the cornea and the back of the sclera would be equivalent to 24 mm
  ask patches with [(pxcor + 80 ) ^ 2 + (pycor) ^ 2 < 20000 and (pxcor + 80 ) ^ 2 + (pycor) ^ 2 > 19000]
  [
    set pcolor red
  ]
  ; call procedures to replace region of sclera with the retinal test patch
  RetinaPatch
end 

; procedure to create test patch region on retina

to RetinaPatch
  ; fills in a region of the retina 2 pixels out from either side of a line that passes from the centre of the light beam through the centre of the lens (line of no refraction for photons)
  ; this region is the smaller depiction of the zoomed in window on the right-side of interface in which the number of rods stimulated will be recorded
  ask patches
  [
    if pcolor = red and (((47 / 130)* pxcor + (31)) >= pycor and pycor >= ((47 / 130)* pxcor + 27) and pxcor >= 0)
    [set pcolor 94]
  ]
end 

; procedure to draw aqueous humour

to AqueousHumour
  ; fill in region between cornea and lens with white (representing the humour)
  ask patches with [(pxcor + 140) ^ 2 + (pycor) ^ 2 < 8761 and -200 >= pxcor]
  [
    set pcolor white
  ]
end 

; procedure to draw lens

to Lens
  ; lens drawn as region contained by two circles with radii equivalent to the anterior and posterior radii of curvature of the lens
  ask patches with [(pxcor + 79) ^ 2 + (pycor) ^ 2 < 14400 and (pxcor + 211) ^ 2 + (pycor) ^ 2 < 5184]
  [
    set pcolor 88
  ]
end 

; procedure to draw vitreous humour

to VitreousHumour
  ; fill in any grey region within the sclera with white (representing humour)
  ask patches with [(pxcor + 80 ) ^ 2 + (pycor) ^ 2 < 20000 and pcolor = grey]
  [
    set pcolor white
  ]
end 

; procedure to draw iris and pupil structure

to irisStructure
  ; first relate pupil slider to size of iris
  ; set the magnitude for the inner y coordinate of the iris to be the radius of the pupil in pixels
  set irisMin ((12 * (Pupil / 2)))
  ; create top half of iris
  ask patches with [(72 >= pycor and pycor >= irisMin and -200 >= pxcor and pxcor >= -203)]
    [
      set pcolor 34
  ]
  ; create bottom half of iris
  ask patches with [((- irisMin) >= pycor and pycor >= -72 and -200 >= pxcor and pxcor >= -203)]
  [
    set pcolor 34
  ]
end 

; procedure to draw retinal cells using rectangles

to retina
  ; set default y coordinates for retinal cells
  set ycell 195
  ask patches [
    if ycell >= pycor and pycor >= -195 [
      ; create retinal ganglion cells which are the lightest blue ones furthest to left
      ask patches with [190 >= pxcor and pxcor >= 175 and ycell >= pycor and pycor >= (ycell - 2)] [
        set pcolor 98
      ]
      ; create bipolar cells wihch are the next cells to the right of the retinal ganglion cells
      ask patches with [210 >= pxcor and pxcor >= 195 and ycell >= pycor and pycor >= (ycell - 2)] [
        set pcolor 97
      ]
      ; create rods which are the longer cells to the right of the bipolar cells
      ask patches with [265 >= pxcor and pxcor >= 215 and ycell >= pycor and pycor >= (ycell - 2)] [
        set pcolor 96
      ]
      ; create retinal pigment epithelium cells
      ; goes all the way across since they're densely packed and are the last layer which then absorbs scattered light
      ask patches with [280 >= pxcor and pxcor >= 270 and 200 >= pycor and pycor >= -200] [
        set pcolor 95
      ]
      ; decrease y values of the retinal ganglion cells, bipolar cells, and rods by 5 on each loop to create evenly spaced cells
      set ycell (ycell - 5)
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; underwater setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; underwater setup procedure that alters the started setup

to underwater
  clear-turtles
  clear-drawing
  set bkgdcolor 1 ; set this variable to 1 to indicate that the background is now blue
  set avgphotons 1000 ; assuming that 1000 photons are entering the water at sea level

  ; set background colour to be blue to represent water
  ask patches with [pcolor = grey and 100 > pxcor] [
    set pcolor 105
  ]

  ; call goggle procedures
  goggles

  ; reset the iris region to be white so it can be replaced by the appropriate pupil size
  ; for the given depth chosen on the slider prior to pressing the underwater button
  ask patches with [ 72 >= pycor and pycor >= -72 and -200 >= pxcor and pxcor >= -203]
  [
    set pcolor white
  ]

  ; set pupil size to increase with depth (based on what is selected on slider)
  ; nwater values are also set according to literature values with respect to depth to simulate
  ; the decrease in light intensity as depth increases
  ; the size of the pupil increases with depth
  if 0 >= depth and depth > -2
  [
    set nwater 0 ; absorption values are based on the shallowest depth, in this case 0 m from sea level
    set pupil 2
    irisStructure
  ]
  if -2 >= depth and depth > -4
  [
    set nwater 0.008355
    set pupil 3
    irisStructure

  ]
  if -4 >= depth and depth > -6
  [
    set nwater 0.01585
    set pupil 4
    irisStructure
  ]
  if -6 >= depth and depth > -8
  [
    set nwater 0.02332
    set pupil 5
    irisStructure
  ]
  if -8 >= depth and depth > -10
  [
    set nwater 0.0303
    set pupil 6
    irisStructure
  ]
  if -10 >= depth and depth > -12 [
    set nwater 0.0394
    set pupil 7
    irisStructure
  ]
  if -12 >= depth and depth >= -14 [
    set nwater 0.0461
    set pupil 8 ; assuming the maximum dilation of the eye occurs at a depth between -12 m and -14 m
    irisStructure
  ]
  if -14 >= depth and depth >= -16 [
    set nwater 0.0506
    set pupil 8
    irisStructure
  ]
  if -16 >= depth and depth >= -18 [
    set nwater 0.6060
    set pupil 8
    irisStructure
  ]

  make-photons
end 

; draw goggles around eye

to goggles
  ; create air pocket between goggle lens and eye
  ask patches with [ pcolor = 105 and 100 >= pxcor and pxcor >= -269 and 145 >= pycor and pycor >= -145]
    [
      set pcolor grey
  ]
  ; lens of goggles
  ask patches with [ -267 >= pxcor and pxcor >= -271 and 145 >= pycor and pycor >= -145]
  [
    set pcolor 89
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; make-photons ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; procedure to make intial photons

to make-photons
  ; set the number of photons per burst with a Poisson distribution centred at the average photons chosen on the slider
  set number_photons (random-poisson avgphotons)
  create-photons Number_Photons
  [
    ; translate mm to pixels and diameter of beam to radius
    set beamradius (0.5 * 12 * beamwidth)
    ; centre light beam around (-300, -564/23) which is the point on the line though the centre of the mens and to the retinal patch when x = -300
    set ystart ((-564 / 23) - beamradius + random(2 * beamradius))
    set shape "Arrow"
    set color 66 ; starting photons are green
    ; the starting y coordinate for the inital photons can be -564/23 +/- the beam radius
    setxy -300 ystart

    ; set up angle of beam (from up as 0°)
    if(bkgdcolor = 0) ; grey background (air)
    [
      set heading 78 ; angle that causes centre of beam to pass through centre of lens and reach retina with no refraction
    ]
    if(bkgdcolor = 1) ; blue background (water)
    [
      set heading 46 ; angle calculated using Snell's Law for refraction that occurs when light moves from air to water
    ]
    set size 15
    pen-down
  ]
  reset-ticks
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; go procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to burst
  ask photons
  [

    forward StepSize ; the photons move forward 1 pixel/tick

     ;;;;;;;; specifying the absorption values for each layer of the eye ;;;;;;;;;

    ; absorption and refraction at cornea
    if pcolor = pink [
      facexy 55 48 ; focal point is just beyond retina
      absorbcornea
    ]

    ; absorption in humours
    if pcolor = white [absorbhumour]

    ; absorption and refraction at lens
    if pcolor = 88
    [
      ; call absorption
      absorblens

      ; if photons reach center of lens, refract
      if pxcor = -180
      [
        facexy 50 47 ; bend to focus light on retinal patch (correct cornea refraction)
      ]
    ]

    ; the iris is the structure that preventing photons from passing, except if they are within the pupil
    if pcolor = 34
    [
      set decays decays + 1
      die ; when the photons hit the iris they die
    ]

    ; underwater media absorption for when underwater procedure activated by button
    if pcolor = 105 [waterabsorb]

    ; refraction at goggles
    if pcolor = 89
    [
      set heading 78 ; based on refraction values in air
    ]

    ;;;;;;;; absorption within right panel of the interface  ;;;;;;;;;;;;;;;;;;;;;;;;

    ; absorption of photons by rods
    if 270 >= xcor and xcor >= 175 ; contains the entire area of the retina on the right panel of the interface
    [
      absorbretina
    ]

    ;; if incident photon hits retinal test patch, moves to random y-coordinate at x = 105 in the retina
    if pcolor = 94 ; the colour of the retinal test patch
    [
      set yline random-ycor ; provides variation along the y-axis of the retina
      pen-up
      set color 67 ; changes the photons to the colour green
      set size 10
      set shape "circle"
      setxy 105 yline
      facexy 300 yline
      wait 0.03 ; create time delay between photon hitting patch and appearing in window, for cosmetic purposes
      pen-down
    ]

    if pcolor = 95 [die] ; absorbed by retinal epithelium layer
    if pcolor = red [die] ; absorbed by the sclera
    if pxcor = 100 [die] ; for initial photons that pass the eye, ensures they don't enter the retina

  ]

  ; if one of the patches changes to the yellow colour, all remaining blue rod pixels change to yellow
  ask patches
  [
    if pcolor = 46
    [
      ask neighbors
      [
        if pcolor = 96
        [
          set pcolor 46 ; changes final colour to yellow
        ]
      ]
    ]
  ]

  ; the following steps are called if the number of rods stimulated is at least equal to the number of photons needed to be
  ; absorbed by rods to elicit a visual response as chosen in the n slider
  if rods-stimulated >= n
  [
  create-bolts 1 ; the presence of a bolt is a visual depiction of a light signal being sent to the brain
    [
      set shape "lightning"
      set color 46
      set size 75
      setxy 140 0 ; the bolt forms to the left of the cells of the retina
    ]
  ]

  ; after all photons have died
  if any? photons = false
  [
    ifelse rods-stimulated >= n
    [
      ; if enough rods have been stimulated for a given burst, "visual response" is shown in the output monitor on interface
      clear-output
      output-write "Visual Response"
    ]
    [
     ; if not enough rods have been stimulated for a given burst, "no visual response" is shown in the output monitor on interface
      clear-output
      output-write "No Visual Response"
    ]
  ]

  ; data for 'average' line of cycles in photons vs time graph

  ; photoncount updates the index with the current photons, in addition value of the array at that tick from past cycles
  ; photoncount is an array that indicates the total number of photons for a given time (tick) value
  set photoncount (replace-item ticks photoncount ((item ticks photoncount) + (count photons)))

  ; currentphotons is a running average of the photons at a given time (tick), across cycles
  set currentphotons ((item ticks photoncount) / (cycles + 1))

  tick

  ; once the green photons enter the zoomed in retina window, but before the retina, gphotons is updated
  ; gphotons is used to calculate the number of photons that successfully entered the retinal patch
  if ticks = 390
  [
    set gphotons (count photons)
  ]

  if ticks = 600 [stop] ; a full cycles has been completed after 600 ticks
end 

to rerun

  burst ; call the single go procedure (burst)

  ; allows 10x cycles each with 600 ticks to be run
  if ticks = 600
  [
    set cycles (cycles + 1)
    reset-ticks
    set gphotons 0
    set decays 0
    resetYellow ; reset the color and state of rods
    clear-drawing
    make-photons
    clear-output
    output-write "Loading ..."
  ]

  if cycles = 10 [stop]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;; absorb ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; when within the pink-coloured cornea region, probabilistic absorption photons occurs

to absorbcornea
  if random-float 1 < CorneaDecay ; calculated absorption/pixel for the cornea
      [
        set decays decays + 1 ; allows for the number of absorbed ('decayed') photons to measured
        die ; these photons do not proceed towards the retina
    ]
end 

; when within the white-coloured aqueous and vitreous humour region, probabilistic absorption occurs

to absorbhumour
  if -180 >= pxcor
  [
    if random-float 1 < AqueousHumourDecay ; calculated absorption/pixel for aqueous humour
        [
          set decays decays + 1
          die
    ]
  ]
  if pxcor >= -180
  [
    if random-float 1 < VitreousHumourDecay ; calculated absorption/pixel for vitreous humour
        [
          set decays decays + 1
          die
    ]
  ]
end 

; when within the lens region, probabilistic absorption occurs

to absorblens
  if random-float 1 < LensDecay ; calculated absorption/pixel for lens
        [
          set decays decays + 1
          die
  ]
end 

; account for the refractive index of water that surrounds the eye when underwater

to waterabsorb
  if random-float 1 < nwater ; nwater changes based on depth, in "underwater setup"
      [
        set decays decays + 1
        die
  ]
end 

; when within the retina region, probabilistic absorption occurs

to absorbretina
  if random-float 1 < RetinaDecay ; calculated absorption/pixel for the retina
  [

    ; if in the blue rods, visually show activated rods with yellow
    ifelse pcolor = 96
    [
      set rods-stimulated (rods-stimulated + 1) ; shows that the rods have been stimulated
      if [pcolor] of patch-ahead 1 != 46 ; change pcolour, as long as the patch 1 ahead is not already yellow (activated)
      [
        set pcolor 46 ; change pcolour to yellow to show activation
      ]
      die
    ]

    ; if not in the retina region, the same retina absorption rate will apply
    [
      set decays decays + 1
      die
    ]

  ]
end 

; used after each cycle to reset the patch colour and remove the lightning bolt

to resetYellow
  ask patches
  [
    if pcolor = 46
    [
      set pcolor 96
      set rods-stimulated 0
    ]
    ask bolts with [color = 46] [die]
  ]
end 

; ISCI 2A18 Enrichment Project 2023
; More detailed information about model in the "Info" tab
; Authors: Jeremy Dykstra and Naya Davidson-Lindfors
; Supervisor: Dr. Cecile Fradin

There is only one version of this model, created 6 months ago by Jeremy Dykstra.

Attached files

File Type Description Last updated
Light to Brain Model.png preview Preview for 'Light to Brain Model' 6 months ago, by Jeremy Dykstra Download

This model does not have any ancestors.

This model does not have any descendants.