Courses‎ > ‎Intro to CS - Full Year‎ > ‎Fall‎ > ‎Dyrland-Weaver‎ > ‎

Work

Submit all assignments here: http://bert.stuy.edu/dyrland/fall2019/pages.py

Solutions to old assignments can be found here: https://github.com/mks21-dw/netlogo

Work 23: 1/6

posted Jan 6, 2020, 11:26 AM by JonAlf Dyrland-Weaver   [ updated Jan 7, 2020, 11:02 AM ]

  • Here is a NetLogo model that you will recreate: http://homer.stuy.edu/~dw/netlogo/zombies.html
    • In it, humans and zombies exist. 
    • The humans are trying to reach safety, represented by the red patches.
    • The zombies are trying to eat the humans.
    • The humans all start on the brown patches.
    • The zombies all start on the black patches.
    • The zombies can detect if there are nearby humans, and move in their direction.
    • If a zombie is within a patch of a human, it eats the human.
    • Even though humans move in the direction of red patches, and zombies move in the direction of a nearby human, all turtles also have a randomness to their movement.
    • The world is standard sized, but wrapping is shut off.
  • The following new NetLogo commands are used:
  1. Create a working version of this model.
  2. If you finished that, add some modifications. Here are some ideas:
    1. Zombies die when they hit the safe zone.
    2. Humans try to avoid nearby zombies.
    3. All turtles have a health property, it decreases each time they move. If health is 0, they die.
      1. Zombies gain health by eating humans.
    4. Anything you'd like to add...
This will be due on Wednesday, 1/8
Submit this as zombies

Work 22: 12/12

posted Dec 12, 2019, 11:43 AM by JonAlf Dyrland-Weaver   [ updated Dec 13, 2019, 5:57 AM ]

Make the following NetLogo program:

Procedures:
  • Setup
    • Clear the screen
    • imports an image
    • creates 100 turtles placed randomly around the world
  • melt
    • have every patch change its color to the color of one of its neighbors.
    • attach this to a forever button
  • fade
    • have every patch decrease its color by .1, but if a color reaches black (any multiple of 10), it should stay there and not go down into the next color band.
    • attach this to a forever button 
  • scratch
    • have turtles rotate randomly and put their pens down
    • have turtles become the color of the patch they are on
    • have turtles move forward an amount based on a slider
      • set the slider to go from 0 to 3 in .1 increments.
    • attach this to a forever button
submit this as netlogo1_review

Work 21: 12/11

posted Dec 11, 2019, 11:40 AM by JonAlf Dyrland-Weaver

Implement Edge Detection in NetLogo.
  • You should start with your program from Work 20, so you have a program that loads an image along with grayscale and reset buttons.
  • Write an edge detection procedure. Some things worth trying:
    • Adding another property to patches to keep track of color differences.
    • Separating the edge-checking for the recoloring (like we did in the image flip assignment)
    • Checking for color likeness using differences between nearby patches.
      • If subtracting, remember that color differences may be positive or negative, but we probably don't care about the sign as much as the value.
      • neighbors or neighbors-4 probably will not be as useful as you want, those will return agent sets, but we want to look at specific values.
      • You may want to look into the shade-of? procedure if you want top try something other than numeric difference.
  • once you have 1 edge detection procedure working, here are things to try:
    • instead of using a single color for edges, use the original color (still set all non-edges to white -or your color of choice-)
    • instead of removing the non-edges, keep them, this creates a cartoon-like effect
    • scale the edge color based on the difference calculation (edges that have a greater difference value are darker)
    • use the shade-of? procedure mentioned above to find edges instead of calculating differences
submit this as edge

Work 20: 12/10

posted Dec 10, 2019, 11:44 AM by JonAlf Dyrland-Weaver

create a NetLogo program with the following:
  • Give patches a property called original_color
  • Write a setup procedure that loads an image file, and then sets original_color for each patch to the newly imported pcolor.
  • Write a reset procedure that sets every patches color to original_color
  • Write a grayscale procedure that changes every patch to the grayscale
submit this as grayscale

Work 19 12/6

posted Dec 6, 2019, 10:46 AM by JonAlf Dyrland-Weaver

Write a NetLogo program that loads an image, and then manipulates the image. 

You should write 3 procedures that work on the image. Some suggestions: replacing colors, reflecting the image (x-axis, y-axis, line), blurring, shifting. You could even try using turtles to mess around with the image (if you use pcolor in a turtle context it will refer to the pcolor of the patch the turtle is currently on). You can do whatever you'd like. Play around. Do not make your NetLogo world too large, it will take far too long to process the image, something like 300x300 is as large as you should go.

submit this as image_fun

Work 18: 12/5

posted Dec 5, 2019, 3:11 PM by JonAlf Dyrland-Weaver

Super important programming note:
  • There is a NetLogo procedure called of
    • It reports the property value of a specific agent.
    • General syntax: [property] of agent
    • Examples:
      • [shape] of turtle 0
      • [pcolor] of patch -12 5
    • Use this wisely
in Netlogo 
  • Write a procedure that loads an image (using the import-pcolors command).
  • Write a procedure that flips an image vertically (aka reflects about the x-axis).
Submit this as photo_flip

Work 17: 12/2

posted Dec 2, 2019, 10:32 AM by JonAlf Dyrland-Weaver   [ updated Dec 2, 2019, 12:44 PM ]

This program will be similar to Friday's "tapestry" assignment. You will also want to change the size of the world to accommodate more (but smaller) patches.
You can find a working version here: http://homer.stuy.edu/~dw/netlogo/on_off.html
  • Pick 2 colors you like, call one of those colors "on" and the other "off".
  • Give patches a property, we will use it later on to keep track of how many neighbors are "on".
  1. Create a setup procedure that:
    1. Clears everything
    2. Sets all patches to the "off" state.
    3. Puts patch 0 0 in the "on" state.
  2. Create a setup_random that:
    1. Clears everything.
    2. Gives each patch a 7% chance of being in the "on" state, otherwise they should be "off"
  3. Create a go0 procedure that does the following:
    1. Every patch should keep track of the number of neighbors that are "on" in the property declared in step 2.
    2. After every patch has completed step 1:
      1. If a patch is "off" and the number of "on" neighbors is 1 the patch should turn "on".
      2. If a patch is "on", and the number of "on" neighbors is not 1, it should turn "off".
        1. This should not include patches that have been turned on just before.
  4. Create a go1 procedure that does the following:
    1. Every patch should keep track of the number of neighbors that are "on" in the property declared in step 2.
    2. After every patch has completed step 1:
      1. If a patch is "off" and the number of "on" neighbors is  in the range [5, 8], the patch should turn "on".
      2. If a patch is "on", and the number of "on" neighbors is not in the range [4, 8], the patch should turn "off"
        1. Like go0, this should not include patches that have just turned "on".
  5. Create a go2 procedure that does the following:
    1. Every patch should keep track of the number of neighbors that are "on" in the property declared in step 2.
    2. After every patch has completed step 1:
      1. If a patch is "off" and the number of "on" neighbors is 3, the patch should turn "on".
      2. If a patch is "on", and the number of "on" neighbors is not 2 or 3, the patch should turn "off"
        1. Like go0, this should not include patches that have just turned "on".
  6. Hopefully you are noticing a pattern to the code you are writing. Create your own version, try out different values of the amount of "on" neighbors that triggers a switch. Maybe even look at values that are not in the same range.
submit this as on_off

Work 16: 11/26

posted Nov 26, 2019, 11:06 AM by JonAlf Dyrland-Weaver

  1. Pick 2 colors you like, call one of those colors "on" and the other "off".
  2. Give patches a property, we will use it later on to keep track of how many neighbors are "on".
  3. Create a setup procedure that:
    1. Clears everything
    2. Sets all patches to the "off" state.
    3. Puts a 2x2 square of patches located near the center in the "on" state.
  4. Create a go procedure that does the following:
    1. Have every patch keep track of the number of neighbors that are "on" in the property declared in step 2.
    2. After every patch has completed step 1 it will do one of the following:
      1. If a patch is "off" and the number of "on" neighbors is  in the range [2,4], the patch should turn "on".
      2. If a patch is "on", it should turn "off"
      • These two options should not happen 
Thismodel works best by changed the world size. The example provided is 101x101 with a patch size of 5.

submit this as tapestry

Work 15: 11/22

posted Nov 22, 2019, 11:31 AM by JonAlf Dyrland-Weaver   [ updated Nov 22, 2019, 11:53 AM ]

On your own, but with consultation of your neighbors when needed, try to recreate the procedures in the following NetLogo program: http://homer.stuy.edu/~dw/netlogo/gdrift.html

Super important programming note:
  • There is a NetLogo procedure called of
    • It reports property values of agents.
    • General syntax: [property] of agent
    • Examples:
      • [shape] of turtle 0
      • [pcolor] of patch -12 5
    • Use this wisely
  1. Phase 1: TO BE DONE BEFORE ANY CODING!
    • Test the buttons & slider out
      • Note: The circle around patch 0 0 is only there to help you identify the center.
    • Using a Key To Success™, answer the following questions:
      • What happens in go?
      • What happens in local go?
      • What do you think happens when you run either procedure for a long time?
      • Can you make any predictions based on the initial amount of patches of different colors?
      • Look at this webpage and think about the model, is there any correlation between the two? http://en.wikipedia.org/wiki/Genetic_drift
  1. Phase 2:
    1. Use the info you gathered in Phase 1 to write your own version of the program.
    2. You must include all the pieces in the original, except for the circle around patch 0 0 
    3. Include your answers to the questions from phase 1 as comments at the top of your code.
Submit this as gdrift.

Work 14: 11/21

posted Nov 21, 2019, 11:34 AM by JonAlf Dyrland-Weaver

On your own, but with consultation of your neighbors when needed, try to recreate the procedures in the following NetLogo program: http://homer.stuy.edu/~dw/netlogo/equalpatchesWeb.html
  1. Phase 1: TO BE DONE BEFORE ANY CODING!
    • Test the buttons & slider out
      • The non-forever go button is there for convenience.
    • Using a Key To Success™, answer the following questions:
      • What are the monitors showing?
      • What does the slider influence?
      • What context are the buttons in?
      • What are the differences between setup and setupEqual?
      • What is the turtle doing to patches?
      • What happens to the patches that the turtle alters?
        • How could you implement this?
  1. Phase 2:
    1. Use the info you gathered in Phase 1 to write your own version of the program.
    2. Include your answers to the questions from phase 1 as comments at the top of your code.
Submit this as equal_patches

1-10 of 25