; ; Friday, September 3rd, 2010 NetLogo StudioIT 1 ITT 134 hands-on lab ; class example ; Main new skill - ; ifelse (condition that is either TRUE or FALSE) ; [ IF its TRUE, here is WHAT to DO in TRUE ; case - often called the THEN clause] ; [ IF condition is FALSE, here is what to DO instead - often called the ELSE clause ] ; ; TO square[ side ] ; Do a turtle SQUARE dance, i.e. ; square of side length SIDE repeat 4 [ fd side rt 90 ] end TO doShow ; doShow procedure - for the doShow BUTTON ca cro numTurtles ; numTurtles is one of the SLIDERS ask-concurrent turtles ; we tried it with ask turtles the [ ; first few times, then changed it ; to ask-concurrent turtles fd 4 pd repeat 36 [ rt 10 square sideLen ] ; sideLen is a SLIDER wait 2 set size 3 pu fd 4 ifelse (remainder who 2 = 0) [ ; ifelse ( condition that is T or F ) set shape "airplane" ; [ Do if TRUE ] fd 2 ; [ Do if FALSE ] if (remainder who 4 != 0) [ fd 3 ] ; We did NOT do this in class set color 85 ] ; here ends the THEN clause, for TRUE [ ; this is the ELSE clause, for FALSE set shape "turtle" set color 45 ] ; end of the ELSE clause of ifelse ( ) pd repeat 18 [ rt 20 square sideLen ] fd 3 wait 2 set size 5 if (remainder who 2 = 0) [ WalkSlowly ] ; we did NOT do this! wait 5 if (remainder who 2 = 1) [ WalkSlowly ] wait 3 if (remainder who 2 = 1) [ SlowlyTwirlYourTurtleSelf ] ] END TO WalkSlowly ; just WAIT till Wednesday for this. ; We did NOT do this yet... repeat 40 [ fd 0.1 wait 0.1 ] END TO SlowlyTwirlYourTurtleSelf ; This is new too. Wait till 09/08/Wed. repeat 180 [ rt 2 wait 0.01 ] ; Waiting 1/100th of a second here. END TO TwirlEvenSlowlyAndOddFast ifelse (remainder who 2 = 0) [ SlowlyTwirlYourTurtleSelf ; then clause, for True ] [ FasterTwirling ; else clause, for False ] END ; The remainder when you divide any number by 2 is either = 0 (TRUE) ; or is NOT EQUAL TO ZERO, i.e. remainder when you divide ; the turtles number by 2 is not 0, is 1, because its an ODD ; turtle with a number like 1 or 7 or 23 or 5 or 9, ; ; instead of an EVEN turtle with a number like 2, 4, 6, 8, or 14 or ; 22 or 100 or 144. TO FasterTwirling repeat 180 [ rt 8 wait 0.01 ] END ; ifelse has THREE PARTS TO IT: ; 1. a CONDITION that is T or F and ; 2. a THEN clause for TRUE actions ; and ; 3. an ELSE clause for FALSE actions