Work

Unless otherwise noted, all assignments are due by 8am the next class day.

All submissions must be made via the homework server: http://bert.stuy.edu/jdyrland/fall2018/pages.py?page=profile

Late homework can be submitted for half credit up until solutions have been posted.

You can find homework solutions here: https://github.com/mks21-dw/racket
                                                                           https://github.com/mks21-dw/netlogo

Work 35: Final Exam Stuff

posted by JonAlf Dyrland-Weaver

Attached to this post you will find 3 files:
  • Copy of the Fall 2011 Final Exam
    • This exam contains some list and recursion questions in racket. You should ignore them.
  • Copy of the Fall 2016 Final Exam
    • Note there is no Racket on this exam, but there will be for you
  • The Final Exam Reference Sheet
    • This will be the same one you will have for the actual final

Work 34: 12/20

posted Dec 20, 2018, 11:44 AM by JonAlf Dyrland-Weaver   [ updated Dec 20, 2018, 12:28 PM ]

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 33: 12/18

posted Dec 18, 2018, 11:07 AM by JonAlf Dyrland-Weaver   [ updated Dec 19, 2018, 11:37 AM ]

Implement Edge Detection in NetLogo.
  • You should start with your program from Work 32, 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 32: 12/14

posted Dec 15, 2018, 12:56 PM 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 31: 12/12

posted Dec 12, 2018, 6:55 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 30: 12/11

posted Dec 11, 2018, 10:44 AM by JonAlf Dyrland-Weaver   [ updated Dec 11, 2018, 1:03 PM ]

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 29: 12/04

posted Dec 4, 2018, 6:39 AM by JonAlf Dyrland-Weaver

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
  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 patch 0 0 in the "on" state.
  4. Create a setup_random that:
    1. Clears everyone.
    2. Gives each patch a 7% chance of being in the "on" state, otherwise they should be "off"
  5. 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 greater than 1, it should turn "off".
        1. This should not include patches that have been turned on just before.
  6. 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".
  7. 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".
  8. 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 28: 11/30

posted Nov 30, 2018, 11:42 AM by JonAlf Dyrland-Weaver   [ updated Nov 30, 2018, 12:30 PM ]

  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. 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 [2,4], the patch should turn "on".
      2. If a patch is "on", it should turn "off"
submit this as tapestry

Work 27: 11/29

posted Nov 29, 2018, 11:20 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/gdrift.html
  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 26: 11/27

posted Nov 27, 2018, 10:42 AM by JonAlf Dyrland-Weaver   [ updated Nov 27, 2018, 11:18 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/equal_patches.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 36