Homeworks-Fall 2005

All homework are due by 10 pm on the due date!

HW1: Implement one new image method in Picture

DUE DATE: Wed 7 Sept

Create a new method in the class Picture that implements some kind of image manipulation. You must use a for loop in your method! The picture that gets manipulated should be the target that receives the method (i.e., this). For example, if you implement the method "mytweak()", then you'll use it on some picture somePicture.mytweak(), and you'll expect the picture somePicture to change. (Don't bother returning a DIFFERENT picture for this method.)

What manipulation that gets implemented is entirely up to you: Increasing blue while decreasing red, flipping vertically, posterizing, etc. You must implement something NOT already implemented in the class Picture. You can use the methods that are there as examples.

Turn your implementation of the class Picture via WebCT. Name your method something that makes sense for what it does. Put your method at the bottom of the class definition, with a comment before it indicating your name and what your method does.

HW2: Create a Picture collage

DUE DATE: Wed 14 Sept

Implement a class with a static public void main() method that, when executed, creates and shows a collage of pictures. You need to have one picture appear four times: The original time, then three other times with some image manipulation. You're welcome to add additional pictures if you'd like. Mirroring the canvas horizontally or vertically often improves the composition of the collage, but is not necessary.

Your method can call FileChooser.setMediaPath() and then use FileChooser.getMediaPath() to access pictures.

Turn in your PictureCollage class, any additional pictures that you add to your media folder to create your collage, and your Picture class if you end up adding any additional methods to it. Turn in via WebCT.

HW3: Create music

Must have at least four parts. At least one of these parts must start later than the rest.

Must use at least two different instruments.

Must be at least 10 seconds long.

Extra Credit: Up to 10 points extra credit if one of the parts is generated algorithmically. If you just have random notes, you'll get 1 point. If you have random notes that match duration (i.e., the random part doesn't go longer than the other parts), you get 5 points. If your notes are actually sonorous (not dischordant) with the rest of the piece and you have a mix of note durations (but still doesn't go longer), you can get up to 10 points.

Implement your music in a MyFourPartSong class in a main method. At the end of your main method, .notate your song. From the notation window, you can write out the MIDI to upload and share with others.

HW4: Use Weaving and Repeating to Create Music

Using the methods developed in class to play with linked list of music, create a song.

You must use weave and repeatNext (or repeatNextInserting) to create patterns in your music. (Which means, of course, that you have to use the SongNode and SongPhrase methods.)

You must use weave and repeatNext (or repeatNextInserting) EACH at least three times in your piece. In other words, repeat a set of nodes, then repeat another set, then repeat another set. Then weave in nodes with one pattern, then weave in nodes with another patter, and then weave in nodes with a third pattern.

You must use at least four riffs from SongPhrase.

You must also create your own riffs in SongPhrase. You can simply type in music, or you can compute your riff – any way you want to do it is fine. Just create at least one phrase (of more than a couple notes) that is interesting and unique.

All told, you must have at least 10 nodes in your final song.

You only have to use SongNode and have a single part with a single instrument.

For +5 points extra credit, use the SongPart class and create your song with more than one part and instrument.

You will create a class (with some cunning name like MyWovenSong) with a main that will assemble your song, then open it with showFromMeOn. (If you use Song and SongPart, you'll use show instead of showFromMeOn.) Please put comments in your class:

With your name, GT-email address

Explaining what you're doing

Turn in to WebCT:

Your song class.

Your modified SongPhrase class.

If you end up modifying SongNode or SongPart, you can include that, too.

Draw a picture of your resultant list structure. Show us where all the nodes are in your final composition. You can do this by drawing with a tool like Paint or Visio or even PowerPoint, or you can draw it on paper then scan it in. You can turn in JPEG, TIFF, or PPT files.

HW5: New Picture List Manipulations

Using any of the linked lists of pictures that we created (where ordering represented linearity, or layering, or using turtles to walk the list), implement three additional methods:

firstpictureinlist.weave(newelement, n) Weave the newelement into the linked list that starts from firstpictureinlist every n nodes until the end of the list.

firstpictureinlist.addToEndNTimes(newelement,n) Put n copies of newelement at the end of the list that starts from firstpictureinlist.

firstpictureinlist.findAndInsertRepeat(oldelement,newelement,n) Find oldelement (it's a node, not a picture, so you can look for an exact match), and then insert after oldelement some n copies of the node newelement.

You must also provide a class named PictureTest that has a main() method which utilizes all three of your new methods. When the grader executes the main(), it should (a) show a background with three or more pictures in it, (b) then show a new picture after weaving a new element into it, and (c) a third picture with some new pictures inserted at the end, then (d) a final fourth picture after using findAndInsertRepeat.

Extra Credit 5 points: Make some of your methods work with PositionedSceneElement, and use them to create a long pattern of smallish images via weaving and repeating, in order to create an interesting tiling on a long picture (e.g., at least 1000 pixels long). Say "dog, dog, house, dog, dog, tree–repeat." Show a fifth picture of some long picture with the tiling pattern appearing on it.

Please put comments in your class before each of the methods that you create:

With your name, GT-email address

Explaining what you're doing:

Each method has a comment explaining itself

Each SECTION of the code, explains itself. For example, "Here's where I'm setting up the original list" and "Here's where I repeat the doggie scaled down to 0.25 five times."

Variable and method names should be clear and understandable.

Turn in to WebCT:

Your modified picture element class (or classes, if you end up modifying more).

Create a tree of images that describe your scene. I'll refer to this as the scene structure.

Create another list with one element per frame containing the sound to be played during this frame. (Could be a rest!)

You can use and modify any of the data structures that we've described in class. To get sounds to link up right, you'll want to use this SimpleSound: SimpleSound.java It has a better blockingPlay(). Download it and put it in your

You will also need to create a class (maybe AnimationRunner?). Your TA will create an instance of this class (AnimationRunner ar = new AnimationRunner()).

The method setUp() sent to the instance (ar.setUp()) should set up the two data structures.

The method play() send to the instance should do the following:

Render the first frame to a FrameSequence instance. (Make sure that the FrameSequence is shown.)

Then, for each frame that you want to generate (There must be at least 20 frames):

Make a change in the scene structure. Any change you want is acceptable.

Render the scene structure.

Play the sound in the frame list element. (Hint: Use blockingPlay() instead of play() on your sound to make the processing wait until the sound is done before moving on.) (Second hint: If your sound is over 1/10 of a second long, you can't get 10 frames per second! These will be short sounds! Want something to play over two frames? Play the first half in one frame, and the second half in the next frame.)

The method replay() should replay the FrameSequence, but won't do the sound, too.

Please put comments in your classes and before each of the methods that you create:

With your name, GT-email address

Explaining what you're doing

Each method has a comment explaining itself

Each SECTION of the code, explains itself. For example, "Here's where I'm setting up the original list" and "Here's where I repeat the doggie scaled down to 0.25 five times."

Variable and method names should be clear and understandable.

Turn in to WebCT:

ALL the classes that you're using for your data structures. (You don't have to turn in Picture, Sound, FrameSequence, or its related structures, but everything you're using for keeping your sound list and scene structure.)

Any additional sounds or pictures you used, besides those in the MediaSources directory.

Create a method soundSave that collects all your sound files and saves them to a WAV file.

Using a tool like QuickTime Pro, read in the JPEG frames (saved by the FrameSequence) into a movie. Make sure that you use a number of frames per second that matches your soundtrack! Then add a sound track to the movie.

You should then (a) make a picture from that filename, (b) open it, and (c) (here's the part that you work at!) open a window with "Tools" in it. These tools should be buttons that will manipulate the picture. It'll look something like this:

You get to choose what tools that you provide, but there must be at least four:

Provide some tool for manipulating the color: Reduce red, increase red, make it grayscale, make it negative, darken, or lighten. Your choice. (You can provide more than one – maybe lighten and darken?)

Provide a tool that takes a numeric input and uses that input to manipulate the picture. Maybe it's a scaling tool and the input is amount to scale (2.0? 0.5?)? Maybe it's an amount to increase or decrease red?

Provide a tool to do some kind of mirroring, either horizontal or vertical.

One other tool of any kind you want. Flip? Red eye removal? Compose a Bratz doll scaled down into the bottom? Chromakey the picture into a jungle?

Everytime that we click one of these tools, the picture should be manipulated and then repainted! We want to see the change after clicking the tool.

Hint: If you need to convert the String from a text field into a Double (with a floating point, like for scaling), you can use Double.parseDouble(String) like this:

> Double.parseDouble("3.45")
3.45

You must also provide a "Save" button that should save the resultant picture back onto the original filename. (Suggestion: Only do this on COPIES of pictures that you want to manipulate!)

When running
Let's consider a timestep to be about a month. Run the simulation for 10 years (120 timesteps). Here are the starting (amazingly simplistic) rules.

If a Person has over 5 neighbors within 20 pixels for three consecutive timesteps, then that person feels overcrowded and decides to emigrate to America.

There is a 0.1% probability for each Person in Europe that they experience crop failure each timestep. If a Person experiences crop failure, they decide to emigrate to America.

There is only 5% chance that someone moves somewhere else in Europe in a timestep, and if they do, they only move between 1 and 16 steps away. (And always within Europe – not into the Atlantic.)

It takes three timesteps to cross the Atlantic. Each of those timesteps/month, there is a 1% chance of dying from disease or other mishap. Be sure to show the People making the journey, about 33 steps per timestep.

Once a Person moves to America, they move more often (20% chance of moving each timestep, in a range of 1 to 100 pixels, but always within America), but disease is more common there. 2% of the population in America becomes diseased (maybe changes color?) each timestep (they don't move when sick). 50% of those ill get healthy again each timestep. If someone is ill for four timesteps in success, they die.

Store to a file the number of people in Europe, in transit, and in America each time step.

Experimentation
You need to build Agent and Simulation subclasses to implement this scenario. But you have to explore and try different things in your simulation.

Run this simulation with these rules, three times.

Now try two other sets of rules and run each of those three times.

Things that you might want to try changing in your rules:

Overcrowding

Maybe there are more people to start with, or it takes more near neighbors to convince someone that they're overcrowded, or more timesteps of crowded conditions to convince them to move

Crop failures

What if crop failures were more common, or it took multiple consecutive crop failures to convince someone to emigrate.

Travel

What if people didn't die on the trip over, or if it took longer

Movement

What if people moved more often, or further, in either America or Europe.

Disease

In America, it was more likely crowded conditions that led to disease. What if people moved like they do in Europe, and they all came ashore at the same 2 or 3 spots, and then the incidence of disease was dependent on the number of people around you?

In addition to your program, you are to produce a Word file with graphs of all NINE of your runs – that's three runs of each of three sets of variables. Show all three variables – Europeans, in-transit, and Americans per timestep for all three of the scenarios that you explored. Explain what you changed in each scenario and why you think the results differed from the other scenarios.

Please put comments in your classes and before each of the methods that you create:

With your name, GT-email address

Explaining what you're doing

Each method has a comment explaining itself

Each SECTION of the code, explains itself.

Variable and method names should be clear and understandable.

Turn in to WebCT:

Your Agent and Simulation subclasses, including your Simulation class if you changed it. Turn in ONE scenario. The TAs don't want three sets of Agent and Simulation classes. Turn in ONE of those sets that works for your scenario, so that the TA can check to make sure that it runs.

A Word file containing descriptions of your different runs, with graphs of results, and explanations of what happened.

EXTRA CREDIT: You can get +5 extra credit points for adding the additional variables of wealth and cost to the simulation and coming up with reasonable rules for how this wealth is used in the simulation. Europeans have a normal distribution of wealth, but the least wealthy are more likely to get sick, more likely to have crop failure, and are more likely to want to emigrate. The most wealthy are the least likely to want to emigrate, are less likely to have crop failure, and are less likely to get sick. Once in America, wealth still plays a factor (most of the Founding Fathers were quite wealthy by their standards). Wealth plays less of a role in movement, but still plays a role in whether you get sick and die. If you decide to go for the extra credit points, please explain what rules you implemented and why – and you still have to explore

HW9: Simulate a stampeding crowd

You must write HW9 using Pair Programming. Announce your pair at Student187. Not working in a pair is a 5% score penalty (i.e., you lose five points from the start.)

DUE DATE: Fri 2 Dec

Using the simulation package developed in class, and replacing the turtle with character images, create a stampeding crowd scene simulation.

SetUp

Have 100 crowd members (villagers? wildebeests?) on the left edge of the world (within 100 pixels of the left edge). All headings are initially set to the right edge.

Have 10 "obstacle" agents scattered in the middle 200 pixels of the world

During the Simulation
Let's imagine that a time step is a minute. Run the simulation for 30 minutes.

The crowd moves relentlessly from the left edge to the right, with a minimum movement each step being 3 pixels, and a maximum of 10 steps.

The crowd doesn't want to be bumping into others. If there are three or more people too close (say within 10 steps), a person will get out of there (pick a random direction and move speed distance away – not a random speed, but maximum speed.) (It's pretty hard to set a heading toward open space, but if you can do it, go ahead!)

Nobody in the crowd wants to be within 10 steps of an obstacle. If someone is heading for an obstacle, and they're within 20 steps of the obstacle, they're going to turn 45 degrees to the left or right (randomly). (What if they're NOW heading for an obstacle, after turning? Better turn again! Find some direction where you're NOT facing an obstacle!)

People change physical position regularly – 25% chance each time step of changing the direction they're facing, 5% chance each time step of doing something else(waving? i.e., putting hand up, putting it down next time step). Implement any other milling about rules (e.g., more position changes) you'd like.

If at the start of a timestep, you're not facing the right edge, start heading back that way. REMOVEDge your heading by 10 degrees each time step to head toward the right edge (e.g., if your heading is 5, and you want to be 90, change to 15).

Please put comments in your classes and before each of the methods that you create:

With your name, GT-email address

Explaining what you're doing

Each method has a comment explaining itself

Each SECTION of the code, explains itself.

Variable and method names should be clear and understandable.

Turn in to WebCT:

Your Agent and Simulation subclasses

Any JPEG characters that you create.

EXTRA CREDIT: There is no requirement to have different types of villagers, but I'll offer up to 10 points extra credit for having three or more types (e.g., maybe 5 points for two types.) One type of villager might look younger and move faster, another might look older and move slower. And maybe there's a maniacal kind that keeps heading for the obstacles! Mark Guzdial