NetLOGO example - for 810:025 Homework #1, Problem #1 preparation and discussion.



We will study and use this example in the Thursday, January 21st StudioIT 1 - ITT 134 2nd floor lab class. Probably discuss it further the following week.

Do NOT worry about understanding it. You will understand the features it includes that are needed for your February 2nd, Ground Hog's Day assignment. We have four more classes to discuss this example and you'll see lots more NetLOGO by then!

There is another example below here that has some additional features and beautiful patterns that show up at the very end of the turtles dance. PD puts the Pen Down, so they can draw some circles and draw some lines on the stage or the grid of patches, aka turtle world.

What you see below here is called a Java Applet. Its very easy to eventually publish your NetLOGO models to your own web site. You will learn how to do that long before spring break gets here.



powered by NetLogo

view/download model file: OddEvenExample.nlogo

WHAT IS IT?

Written on January 19th, 2010 to be used as an example to help with homework assignment #1 problem #1 which requires the EVEN and the ODD turtles to do different things. The homework is NOT DUE UNTIL February 2nd so there are FOUR classes BEFORE HW #1 is due.
Plenty of time to cover the concepts of NetLogo REMAINDER, the WHO number that all NetLogo turtles have and finally the NetLOGO ifelse statement that allows you to specify different things to happen depending on the WHO number of the turtle.


HOW IT WORKS

If you divide any whole number (integers are whole numbers) by 2, the remainder will be 0 for all EVEN numbers and the remainder will be 1 for all ODD numbers. Every turtle has a WHO number and that WHO number is just a positive INTEGER.


HOW TO USE IT

Click on the Odd and Even Demo button to see the NetLogo application in action.


THINGS TO NOTICE

         
ifelse remainder who 2 = 0             
    [  set color green    repeat 360 [ lt 4 wait 0.01 ]  ]
    [  set color yellow   repeat 360 [ rt 4 wait 0.01 ]  ]   

Some turtles end up getting colored GREEN.

Some turtles end up getting colored YELLOW.

Some turtles, the EVEN ones, the GREEN ones, rotate counterclockwise.
If a turtle rotates 4 degrees to the left with "lt 4" and does that 360 times,
it will be a dancer rotating or spinning counterclockwise for FOUR full spins.

If a turtles has a WHO number which is ODD, then remainder who 2 = 0 is FALSE,
because the WHO number divided by 2 leaves a REMAINDER of 1, not 0.

In that case, the turtle turns YELLOW and then rotates CLOCKWISE using rt 4,
to turn right 4 degrees 360 times.

Since we wait 0.01 seconds after each rt 4 turn, that 1/100th
second pause
after each 4 degree turn to the right makes it look as if the turtle is doing
a smooth twirl.

Here is what happens to the ODD turtles!

                 
[ 
   set color yellow  
   repeat 360 
         [  rt 4 
            wait 0.01  ]   
]  

How long does the twirling clockwise or counterclockwise last?

360 multiplied by 0.01 = 3.6 seconds.

Here is what happens to the ODD turtles, formatted differently.

[                        
   set color yellow          ;; become a yellow turtle
     
   repeat 360 [                                     
                 rt 4           ;; rotating right 4 degrees 
                                    
                 wait 0.01      ;; waiting 1/100th second 
              ]                      
] 

Does it seem like about 3 1/2 to 4 seconds that the GREEN and the
YELLOW turtles spin as they dance together?

         
ifelse remainder who 2 = 0
       [  set color green     repeat 360 [ lt 4   wait 0.01 ]   ]    ;; EVEN turtles
       
       [  set color yellow    repeat 360 [ rt 4   wait 0.01 ]   ]    ;;  ODDturtles

THINGS TO TRY

Just play around with it. Don't worry about understanding it until after we talk about it and use it and modify it in lab and follow-up lecture classes.


EXTENDING THE MODEL

Add music or sound effects to it. Do NOT get me started. This could be expanded with so many ideas its not even funny! But it would generally always be FUN, once you get the hang of NetLogo to come up with and try ideas and play with a model or an application.


NETLOGO FEATURES

The remainder feature of the NetLogo language is to be discussed later.

The changing of the size of the turtles is shown.

Changing the color of the patches is shown. Note it is pcolor and not color for PATCHES.


RELATED MODELS

Perhaps later I will fill this in.


CREDITS AND REFERENCES

http://www.cs.uni.edu/~jacobson/025/logo/evenOddIfElseNetLOGO.html