powered by NetLogo
view/download model file: FlyFishing.nlogo
Thursday, January 21st, 2010 - StudioIT 1 - ITT 134 first lab class. Covered NetLogo turtle graphics introduction with emphasis on the ifelse statement and the remainder operation.
TO fishOrAirplanes ca ;; clear all previous drawing and turtles cro 16 ;; create 16 ordered turtles ask-concurrent turtles [ set size 3 ifelse (remainder who 2 = 0) [ fd 3 wait 3 set shape "airplane" wait 2 pd set pen-size 4 fd 8 ] ;; EVEN TURTLES become airplanes [ fd 6 wait 3 set shape "fish" wait 2 pd fd 3 pu fd 1 ] ;; ODD turtles become FISH ] END
It is meant to be played with here. How it works will be explained in future classes, as needed, to help you get better at NetLogo and the modeling and simulation we need to learn by playing with it.
Play with it and look at the output. Try all the buttons first and only AFTER you try the 3 different buttons, start to mess with the SLIDERs to adjust the number of turtles you want to see draw squares, or the other slider for the number of turtles you want to see play the SHAPES game. Also, there are two SWITCHES. Try turning each switch to its opposite setting to see all turtles with one color and to see the turtle shapes without the turtles moving at all.
Notice the planes get larger when they eventually fly away and off the grid, off the screen, out of this patches world. Or do they? If the world is a TORUS, perhaps they are still flying in it, but with HT, the airplanes have become Hidden Turtles. HT is the Hide Turtle command.
What math was used to get a good estimate of the distance that the airplanes would have to travel to fly a full 360 degree circle around the outside of the Patches turtle graphics grid world? Recall it was a world that is 33 wide and 33 tall.
About what would be the diameter of the circle needed? What would the circumference of that circle be?
I had each airplane go forward with the fd command just a little bit and then had each airplane turn to the right with rt 1 or turn to the left with the lt commands, i.e. lt 1 to turn left just 1 degree. I had them turn only 1 degree, so when they repeated this 360 times they would be facing the exact same heading as when they started the "FLY AROUND" of the fishes world. REPEAT 360 [ fd howMuchWouldBeAnEducatedGoodGuess rt 1 wait 0.02 ]
The fish swim off the patches world and use HT too. There are still invisible fish on the grid that you cannot see, but they have stopped swimming. Luckily, they are Hidden Turtles via HT.
Here is the key to the above Flying and Fishing animation: ifelse (remainder who 2 = 0) [ fd 3 wait 3 set shape "airplane" wait 2 pd set pen-size 4 fd 8 ] [ fd 6 wait 3 set shape "fish" wait 2 pd fd 3 pu fd 1 ] Every turtle has a WHO number. REMAINDER who 2 gives a remainder of 0 (zero) for all turtles who have an EVEN who number. REMAINDER who 2 gives a remainder of 1 for all turtles that have an ODD who number. Here is the general pattern that you apply: ifelse (remainder who 2 = 0} [ what to have the EVEN numbered turtles do ] IF CLAUSE part [ what to have the ODD numbered turtles do ] ELSE CLAUSE ifelse ( something that is either TRUE or else it is FALSE ) ---- [ what to DO if it was TRUE ] Do this first [ ] part if TRUE [ what to do if it was FALSE ] or ELSE do this 2nd [ ] part if it was FALSE ifelse ( logical condition - True or False condition ) [ TRUE actions ] also known as THEN clause [ FALSE actions ] also knows as ELSE clause
You can tinker with and add lots of features to this model as you try things.
TINKERing with existing models was the main lesson of the 2's day class on 02/02/Twosday, Ground Hog's day lab. Tuesday/02/02 is indeed a 2's day if there ever was one!
How do you make a smooth move from one place to another?