Lecture: 11-21-2012

posted Nov 21, 2012, 5:54 AM by Samuel Konstantinovich   [ updated Nov 21, 2012, 10:45 AM ]

Homework:

-Watch tutorials 6 and 7. Make sure you can complete the Exercises

-Complete the lab over break.

Goal: Making a basic netlogo program with widgets. (buttons and stuff)

Do Now: (On Paper) Please log in while doing your do now to save time later.

Note: when you see the word PROCEDURE or FUNCTION, that means you have to write a function like in yesterday's lecture notes. 

  1. Write an observer context procedure that creates 5 turtles. They should all be twice the normal size, look like cows, and blue. They should also move a random distance away from the origin. (the random command is random N, and returns any integer from 0 to N-1.) Since the function is observer, you need to use the optional [command] block from the create command to do this. 

  2. Write a turtle context procedure called wiggle. This function moves a turtle by 0.5, then rotates the turtle left a random number of degrees between 0 and 29 degrees (inclusive), then rotates the turtle right by 0-29 degrees as well.

  3. Compare your results with your neighbors.

Lab Work: To be completed over break along with the tutorials. You need a working model by Tuesday.

    Introduction:

  1. Make a netlogo project, save it as “basicMovingTurtles.nlogo” Before class ends you will want to email this to yourself or put it on a flash drive.

  2. Write the setup and wiggle procedures from your do now.

  3. Make a button called setup, that calls the setup procedure. Make a button called go, that calls wiggle and check off ‘forever’. Your buttons should only have 1 command in each of them. This means that your code tab has all of your written work, so that you don't have to look through all the buttons one by one. 

  4. Test if your setup/go buttons work BEFORE you continue.

      Improvement

    1. Add a SLIDER that goes from 1 to 20. Name the slider NUM_TURTLES

    2. Change your setup function by replacing the number 5 in the create command with NUM_TURTLES. Your slider should now affect how many turtles your setup button creates. This is how sliders are used to change your programs.

    3. Now make a slider that changes the starting size of the turtles, you can make the increments 0.5 instead of 1.

    4. Make two buttons, one that calls pen-down, the other that calls pen-up.

    5. Take a minute to email yourself a copy of the program before you forget at the end.

    6. Make a input, that lets you choose the starting color of the turtles. Notice that there are different types of input. Which type should you select?Try to make a second 'chooser' widget to select the starting shape, remember to use a string.

    7. Look at the hatch command in the dictionary. Write a function that has a turtle hatch two children, then die. Suggestions: You can make it interesting by hatching each child separately, so you can issue different commands in the [command] block make them face different directions when you hatch them.

    8. Add at least one other features to your go button. These functions can have the turtles do other things. (Be careful you don't have the turtles hatch every step or you will have a LOT of turtles.)

      Example: Make a function that changes the colors of a turtle randomly. A color is just a number from 0 to 159.9 or so. Numbers ending in 5 are the standard colors. (Look at the color chooser in tools to get an idea)


Comments