The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.


Mouse-Trap Nuclear Reaction

This project is based on this video. Which in turn is modeling the results of an uncontrolled nuclear fission reaction encased within a neutron reflecting sphere (or box).


powered by NetLogo

view/download model file: MouseTrapPingPong_Nuc.nlogo

PROCEDURES

; Remember a semicolon designates a comment

;;;;;;;;;;;;;;;;;;; PROJECT INFORMATION ;;;;;;;;;;;;;;;;;;
;
;    PUT-YOUR-FULL-NAME-HERE
;    CLASS-GOES-HERE
;    DATE-GOES-HERE
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;; BREEDS & AGENTSETS SECTION ;;;;;;;;;;;
; 
; BREED
; A breed is a type of agent-set, that is a group of agents
; that have their own name that you can use to refer to 
; them. You MAY need to use breeds if you want to have 
; more than one type of turtle. Example:
;
;     breed [mice mouse]
;     breed [frogs frog]
;
; The code above creates two different types of turtles. 
; They are still turtles and using the word turtle will 
; refer to both types of breeds. But if I wanted to just
; refer to one type I can know use the specific name.
; Example: 
;
;     create-mice 50
;     ask mice [ set color white ]
;     create-frogs 50
;     ask frogs [ set color green ]
;   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  

;; If you need any breeds, put them here.






;;;;;;;;;;;;;;;;;;; VARIABLES SECTION ;;;;;;;;;;;;;;;;;;;;
; 
; There are several ways to make variables:
;
; GLOBAL VARIABLES
; Are variables that all Agents (turtles, patches, links, 
; observer) can see and use. They can be created in two ways:
;
;     1. You can add a chooser or slider to the Interface window.
;        This will create a global variable with a name you define.
;
;     2. You can declare a global variable in the section below
;        at the top of your program. Example: 
;
;            globals [ number-of-trees ]
; 
; AGENT VARIABLES 
; Are variables that only select agents can see and use. 
; There are two kinds:
; 
;     1. Built-in variables exist, which you can use and
;        sometimes change. Examples include:
; 
;            Turtle Variables: color, xcor, ycor, heading
;            Patches Variables: pcolor, pxcor, pycor
;     
;     2. User-defined variables you can create yourself.
;        And you get to choose who owns them. Examples:
;    
;            turtles-own [ energy ]
;            patches-own [ radiation-level ]
;
; To create agent variables, declare them in the section 
; below (at the end of this comment). 
;
; LOCAL VARIABLES
; Are declared within a function (prodecure) and can only be 
; seen and used within that function. DO NOT declare local 
; variables in this section. Declare them inside the function 
; that uses them using the let keyword. Example:
;
; to eat-sheep
;    let prey one-of sheep-here     ;; prey is a local variable
;    if prey != nobody
;       [ ask prey [ die ] ]
; end
;   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; If you need any global or agent variables, put them here.
                         
turtles-own [ speed ]







;;;;;;;;;;;;;;;;;;;;;;;;; SETUP SECTION ;;;;;;;;;;;;;;;;;;
;
; Use this section to implement all of the procedures that
; relate to the setup button, and are to run when the 
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                      
                                              
           
to setup
  clear-all            ;; Resets everything, makes screen blank.
  setup-patches        ;; Calls the setup-patches function.
  setup-turtles        ;; Calls the setup-turtles function.
  
  ;; The do-plots function is at the bottom of the page.
  do-plots             ;; Calls the do-plots function.
  
end

to setup-patches
  ;; Put your code to setup your patches here.
  ask patches [set pcolor orange ]


end

to setup-turtles
    ;; Put your code to setup your turtles here.
    
  set-default-shape turtles "circle" ;; Change cow to the shape name that you wrote down. 
  create-turtles starting-balls
  [
    set color white
    set size 0.5  ;; easier to see
    set label-color blue - 2
    setxy random-xcor random-ycor
    set speed random 100
    rt random-float 360
  ]


end







;;;;;;;;;;;;;;;;;;;;;;;;; GO SECTION ;;;;;;;;;;;;;;;;;;;;;
;
; Use this section to implement all of the procedures that
; relate to the go button, and are to be called when the 
; program is running.
; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    



to go

  let orange-patches count patches with [pcolor = orange] ;; count number of orange patches
  if orange-patches <= 0 [ stop ]
    
  move-turtles
  check-patches
  
  ;; The do-plots function is at the bottom of the page.
  do-plots             ;; Calls the do-plots function.
  
  tick   
  
end



to move-turtles
  ask turtles [
    fd speed                              ;; just like move
    set speed speed - random 5              ;; slow ball by some amount 
    if speed <= 0                           ;; is ball still moving?
     [ set speed 0 ]
  ]

  
  
  
end
  
  
to check-patches
  ask patches [
      if pcolor = orange [
          let ball one-of turtles-here       ;; grab a random ball if one is here
          if ball != nobody [                ;; did we get one?  if so,
            
              ask ball [     
                  set speed random 100       ;; give it a random speed
                  rt random-float 360        ;; and direction
                  
                  hatch 2 [
                      set speed random 100       ;; give it a random speed
                      rt random-float 360        ;; and direction
                  ]
                    
              ]    
                           
              set pcolor black               ;; make this square black
  
          ]
      ]
  ]
  
  
  
end






;;;;;;;;;;;;;;;;;;;;;; PLOTS SECTION ;;;;;;;;;;;;;;;;;;;;;
;
; Use this section to implement all of the procedures that
; relate to plotting information (graphing information) 
; in the interface window.
; 
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    


to do-plots
  
 let orange-patches count patches with [pcolor = orange] ;; count number of orange patches
 
 set-current-plot "Reaction" ;; which plot we want to use next
 
 set-current-plot-pen "unsprung-traps" ;; which pen we want to use next
 plot orange-patches ;; what will be plotted by the current pen
 
 set-current-plot-pen "balls-released" ;; which pen we want to use next
 plot count turtles           ;; what will be plotted by the current pen
  
end