Computational Modeling and Simulation - Fall 2012
The applet requires Java 1.4.1 or higher. It will not run on Windows 95 or Mac OS 8 or 9. Mac users must have OS X 10.2.6 or higher and use a browser that supports Java 1.4. (Safari works, IE does not. Mac OS X comes with Safari. Open Safari and set it as your default web browser under Safari/Preferences/General.) On other operating systems, you may obtain the latest Java plugin from Sun's Java site.
powered by NetLogo
view/download model file: IfElseAug24th2012.nlogo
Friday, August 24th, 2012 CS 1025 Computational Modeling and Simulation example - Followup/to be continued on Monday 08/27 in class #4)
Try out stagger2 first. It is simpler and does NOT use ifelse to make EVEN turtles do something different from the ODD turtles. CLICK THE TOP BUTTON and watch stagger2 at work.
Try it out with different numbers of turtles. The SLIDER allows you to set the number of turtles that a created.
The SLIDER is set to a minimum value of 4, maximum value of 128, increment value of 4. Try it out by dragging on the thumb, or by clicking to the left or right of the thumb.
TO Stagger ca ;; ca is short for the clear-all command, an Observer Command ;; ca clears out EVERYTHING in preparation for something new, doing ;; doing clear-turtles, clear-patches, clear-drawing. What are PATCHES? Don't worry! cro howManyTurtles ;; howManyTurtles is the name of the SLIDER ask-concurrent turtles [ ifelse (remainder who 2 = 0) [ slowWalk set shape "airplane" slowWalk changeColorEven ] [ slowerWalk wait 1 changeColorOdd ] ] END
TO slowWalk repeat 60 ;; 60 times 0.1 = 6 so "fd 6" would achieve the same result as "fd 0.1" done 60 times. [ fd 0.1 ;; forward 0.1 of a step. wait 0.05 ;; wait 1/20th of a second, i.e. pause 5/100th of a second ] end
TO Stagger2 ;; all the turtles do the SAME THING ca cro howManyTurtles ask-concurrent turtles [ fd 5 wait 0.1 ;; wait 0.1 of a second pd ;; put your pen down using pd command so you DRAW ;; (leave a trail and drag your tail ;; when you walk fd forward or bk backward) slowWalk ] END
TO changeColorOdd wait 4 set color white wait 1 repeat 72 [ rt 5 wait 0.01 ] wait 0.5 set shape "fish" changeSize END TO changeColorEven ;; the EVEN turtles become YELLOW and do a full 360 degree twirling rotation. wait 5 set color yellow wait 1 repeat 144 [ rt 2.5 wait 0.01 ] changeSize END
TO changeSize repeat 20 [ set size size + 0.1 ;; size goes from 1 to 1.1 to 1.2 to 1.3 to 1.4 to 1.5 to ... to 2.8 to 2.9 to 3.0 wait 0.1 ] END