posted Jan 23, 2014, 9:48 PM by Samuel Konstantinovich   [ updated Jan 24, 2014, 6:15 AM ]

Here is the last exam with solutions. I truly apologize but due to the unavoidable time constraints that my absence and health issues caused, I was not able to return it in a timely manner. Please feel free to look over the exam and solutions over the weekend for additional practice. I will post the grades on the Homework server. 

You are working on the edge detection lab today. 

Remember to use the patch-at command to easily access the neighbors. Example: Patch-at 1 1   refers to the patch up+left from the current patch. use the dictionary!

IMPORTANT Fill out this form:

1. Have all patches decide if they should be an edge.
THEN (meaning after the 1st operation is completed by EVERY patch)
2. Have all patches that are edges change to an edge color. Optionally make the non-edges change white.

For part 1:
 Calculate the vertical and horizontal difference and compare those numbers to a deciding number. You can make the deciding number in the calculation a slider, so you can adjust the sensitivity. 

For part 2:
Edges can be: 
-Colored based on the original color of the patch
or (more challenging)
-A shade of grey based on how strong the edge is.

01-21-2014 Color Lab

posted Jan 22, 2014, 7:27 AM by Samuel Konstantinovich   [ updated Jan 22, 2014, 7:27 AM ]

You are making a image manipulation program that has the following buttons:
1.loadImage - loads a predetermined image file
2.grayscale - after loading the image, converts it into a black&white picture
3.replace - replaces a startColor with an endColor, these are variables from the color choosers.

There are two color choosers:
To make a color chooser, add an input , then change the 'type' to color. This will allow you to click any colors you want. 

4. Invert - inverts dark/light colors.

Every color's 1's digit should be pivoted around the 5. 
16 -> 14
22 -> 28
108-> 102
14-> 16
Basically if the 1's digit is x, it becomes 10-x

When a number ends in 0, that is a special case, and you should change it to end in 9.9

Here is an example of what EVERYONE should have:
Notice the car dark/light was inverted, and the reds were replaced with greens. 
I could replace any color with any other color if I wish by changing the start/end colors on the color pickers.

00 - Practice Finals

posted Jan 15, 2014, 8:59 AM by Samuel Konstantinovich   [ updated Jan 15, 2014, 8:59 AM ]

You can view your practice Finals here, along with the reference sheet.

I strongly suggest you work on one of them over time, and time yourself on the other one. 

Solutions won't be posted, but you have unlimited time, and you have a computer to test your answers. Feel free to collaborate and discuss if you are stuck.

01-08-2014 Final Project Specifications

posted Jan 8, 2014, 7:02 AM by Samuel Konstantinovich   [ updated Jan 15, 2014, 8:59 AM ]

Final Project Submission format:

You are submitting a zip or rar file to the homework server on or before Monday January 20th. (Deadline Jan 20th 11:59pm)

You can download a program to zip/rar files if you don't already have one. 
Windows: WinRar
Mac: iZip
If you aren't sure how to use them watch a video tutorial.


Save a new copy every day, and merge your code with your partner's code before the end of class the next morning. That is your "current working version" 

Save each current working version as FinalProjectXX, where xx is the date, 08,09,10, etc.

You can make more than 1 revision in a day in case you want to keep track of more changes by adding a letter:

I will look at the highest number that you submit as your final copy. 

You will also need a Log of all changes (changelog.txt) made to your project as well as who made the changes. This should say the Date and who made the change and if it was a:
+new function you wrote / what they did
+functions you modified
+What bugs you found / fixed

Jan 8th
Added player movement. 
new functions: playerstuff, checkborders
Added a map with colors. 
new functions: Setup, patchstuff
Bug: Map doesn't always refresh

Jan 9th
Fixed map bug.
Added Map animations
New Functions: Mapstuff
Modified Functions: patchstuff
Added map animation. 
Added monsters 
Player can see monsters
new function: monsterMash, monsterMotion
modified functions: playerstuff


posted Jan 7, 2014, 5:57 AM by Samuel Konstantinovich   [ updated Jan 7, 2014, 5:57 AM ]


breed [ bullets bullet]
breed [ players player]

players-own [speed rotatespeed bullettimer]
to setup
  ;ask patches [set pcolor red]
  create-players 1

to go
  ask players [moveplayers]
  ask bullets [movebullets]
  ;ask patches [set pcolor pcolor + 10]
  wait 1 / 30

to movebullets 
  fd 1
  if abs pxcor > max-pxcor - 1 or abs pycor > max-pycor - 1
  [ die ]

to moveplayers
  fd speed
  rt rotatespeed
  if bullettimer > 0 [ set bullettimer bullettimer - 1]

to shoot
  ask players [ 
    if bullettimer = 0 [
      set bullettimer bulletdelay
      hatch-bullets 1 [set shape "circle"]]]

to up
  ask players [accelerate acceleration ]

to down
  ask players [decelerate acceleration ]

to leftkey
  ask players [leftbias rotationalacceleration]

to rightkey
  ask players [rightbias rotationalacceleration]

to accelerate[n]
  set speed speed + n

to decelerate[n]
  set speed speed - n

to leftbias[n]
  set rotatespeed rotatespeed - n

to rightbias[n]
  set rotatespeed rotatespeed + n


posted Jan 2, 2014, 5:19 AM by Samuel Konstantinovich   [ updated Jan 2, 2014, 5:19 AM ]

Goal: You will learn to make breeds behave in different ways depending on their state. 
It is really important to realize that color and shape do not determine breed. 

Ack Monsters! Activity 

There are two breeds: monsters and towers.
Monsters need variable to keep track of the state. You can store a string or a number, it doesn't matter.
The monsters should be gray, and you can import a "monster" shape from the turtle shape editor. 
The towers should be white, and "house" shaped. 

You need sliders for:

Create num_towers towers, and num_monsters monsters.
All turtles should be size 2 and placed randomly on the world. 

Every time the program runs go:

Patch behavior:
-all the patches are black unless they are lit by a tower.

Tower behavior: 
-rotate by rotate_speed degrees
-project a cone of light that turns patches yellow.
-the cone is tower_angle degrees wide, and tower_radius long

Monster behavior:
-Monsters on a yellow patch turn "scared" 
-Monsters on a black patch turn "angry"
-Make the monsters have different shapes for angry and scared states. 

--Angry monsters:
---Fade* to color 2.
---Wiggle at a speed of .3 and random angle of 30. This makes the monster travel across the screen like a normal wiggle. 

-Scared monsters:
 ---Fade* to color 8.
 ---Wiggle at a speed of .1 and random angle of 360. This makes the monster wiggle in place like they are scared. 

*Fade that means the monster changes its color by 0.25 towards that color every time go is run so that the color changes slowly.

12-20-2013 Prototype

posted Dec 21, 2013, 8:27 AM by Samuel Konstantinovich   [ updated Dec 22, 2013, 1:24 PM ]

Attached is the prototype sample.

I am asking for a written/pictoral description of your project. There is NO CODE to be written at all. 


posted Dec 19, 2013, 5:42 AM by Samuel Konstantinovich   [ updated Dec 19, 2013, 10:47 AM ]

5 Urgent Points:
1. You have a test tomorrow. Worry about that first.
2. If your zombie1.nlogo was really bad, and your partner is suffering, you will fix it by tomorrow. Email them the copy directly.
3. If your partner hasn't provided you with a working zombie1 lab, and you didn't get a different person's working one in class, a link to a working one will be provided for you tomorrow. 
4. In your zombie2 lab, comment at the top which copy you were working on. (Either your partners, a differnet persons, or the one I provide)
5. Submit zombie2.nlogo by Monday 11:59pm on the homework server.

Humans vs. Zombies part II, revenge of the ... zombies?

copy the zombie1.nlogo from your partner's folder to your folder using cp:

cp target_file_and_path new_file_and_path
such as

cp  ../user.name/Documents/zombie1.nlogo  ~/Documents/zombie2.nlogo
this means:
copy   user.name's zombie from documents, into    your Documents using the name zombie2


New Human Behavior:
-Humans with stamina < 4 change shape to a "tired_person"
-Use the shapes editor to make a tired person spend no more than 2 minutes to do this.

New Zombie Behavior:
-Zombies should change their shape and color every 2 ticks. 
-Zombies should change their shape between two "zombie" shapes. 
    If you made a "zombie" shape make a 2nd shape that is slightly different than the original zombie shape. 
    If you didn't make a zombie shape, make a 2nd person shape, (other than tired person) that is slightly different from the original person.
-Zombies now search for humans using a cone of vision, this has several consequences:
   -Zombies have not only a vision radius, but they need a vision angle as well (make a slider)
   -Zombies only detect humans in their cone of vision
New interface element:  Make a toggle switch viewableCones. This will be true or false depending if the switch is on or off.

-When viewableCones is toggled on: Make the zombies change the color of the patches in their vision cone to yellow. Patches that leave the vision cone should revert to black.
-Use ticks to smooth your animation.

Make a 5x5 square of blue patches somewhere on the board. Zombies cannot step on these patches, if they do, they must immediately move backwards.
These blue patches should not be changed to yellow by the zombie vision cones. 


posted Dec 18, 2013, 5:22 AM by Samuel Konstantinovich   [ updated Dec 18, 2013, 5:22 AM ]

Lab: Zombies vs Humans

1. Overview:

-You will work on this today. Do not work with you partner on this project, if you want help, please ask someone else. After tomorrow you will be required to swap your file with your partner, and add new features to your partner's code. This means you should be writing things in a readable and clear way (no crazy variable names or poor spacing/newlines)

2. Zombie Behavior:

-When there is a human in a radius of zombie_vision_radius (make a slider), the Zombies chase after the closest human at a speed of 1. Otherwise they shamble. Shamble is a slow wiggle (.3 speed). 

-When a zombie catches a person (the person is on the same patch as the zombie) the person dies, and a new zombie is created it should look like the other zombies. 

3. Human Behavior

-Humans normally wiggle.

-When one or more zombies are closer than human_vision_radius (make a slider) units away, they try to run from the zombies.

 -When a person is running they check their stamina. 

When there is 2 or more stamina, the person move away from the nearest zombie at speed 1.5. When there is less than 2 stamina, the person just wiggles away from the nearest zombie. People start with maximum_stamina (make a slider). Their stamina decreases by 2 every time they successfully run.

-When a person wiggles, they rotate randomly, then move forward .5 and they also they gain 1 stamina (but no more than max_stamina.

4. Miscellaneous:

- Make Sliders for starting_zombies ( 1-20), starting_humans (1-100)

- Make Slider for maximum_stamina (20-100)

- Make Sliders for zombie_vision_radius, and human_vision_radius

- Make Monitors for : the number of zombies and the number of humans

- Your project should run at an appropriate speed.

- Zombies are all green, humans are all orange.

- OPTIONALLY AT HOME: make a custom shape “zombie” in the shapes editor (spend NO MORE THAN 2 minutes on this) Make sure you duplicate the “person” shape instead of just editing it, or you will lose the person shape.


posted Dec 17, 2013, 5:30 AM by Samuel Konstantinovich   [ updated Dec 17, 2013, 3:48 PM ]

A. Scheme Practice 

Write a scheme function (shuffle A B) that takes two lists A and B, and returns a new list with the elements of both the lists shuffled together in alternating order, starting with the first element of A. 
(shuffle '(a b c) '(1 2 3))  returns:  (a 1 b 2 c 3)
(shuffle '(red foo) '(sky blue)) returns: (red sky foo blue)

When one of the lists is longer than the other (see below) then it shuffles as many elements as it can, then uses the remaining elements of the longer list.

(shuffle '(x y) '(a b c d)) returns: (x a y b c d)
(shuffle '( hey yah) '() ) returns: (hey yah)

Exam: Friday: Does not include Breeds. 

Today we will talk about breeds. Here are new commands you should know:


There are lots of commands like ask  which aren't new, but have added features with breeds. You can ask a breed like ask cars, or ask sheep. You should look at the commands that have <breeds> in the netlogo dictionary, as they are available to you to use.

Sample in-radius commands:

;this paints the patches in a circle white
to colorRadius  ;turtle OR patch context
    ask patches in-radius 8 [set pcolor white]

;this tells you how many nearby turtles there are:
count turtles in-radius 5

Code from class:

breed [cars car]

breed[ wolves wolf]

to setup


  set-default-shape wolves "wolf"

  set-default-shape cars "car"

  create-wolves 5 [set size 2]

  create-cars 5 [set size 3 fd 4]



to go

  ask wolves [wiggle]

  ask cars [carStuff]

  wait 0.05


to wiggle

  rt random 40

  lt random 40

  fd 1


to carStuff

  let x wolves in-radius 5

  if any? x

  [face min-one-of x [ distance myself]]

  fd .5


1-10 of 65