Homeworks-Spring 2007

HW1: Implement two new image methods in Picture

DUE DATE: Monday Jan. 22

Write two new methods in the class Picture that implement some kind of image manipulation.The two methods can not be the same.You must use a for loop in one method and a while loop in the other! 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, but do not make any calls to those existing methods to implement your new methods.

Turn in Picture.java file via WebCT. Name your methods something that makes sense for what it does and place those names in the top comments region of the Picture.java class definition. Place your methods at the bottom of the class definition, with a comment before it indicating what your method does.

The TA grading this homework will compile your Picture.java file in DrJava and test it using the Interactions pane. They will create an instance of a Picture, execute each of your defined methods on that Picture object and show() the results.

HW2: Create a Picture collage

DUE DATE: Friday Jan. 26

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.

The whole collage should be mirrored in some direction – i.e., should be symmetric horizonatlly or vertically. However you may NOT use any of the mirror methods in Picture. You have to place elements such that everything gets mirrored appropriately.

Hint: If you use two turtles, and move/drop everything the same with the two turtles, but mirrored, a symmetric picture will result.

You must use a Turtle to do some of your drawing!!

Your method must use FileChooser.getMediaPath() to access pictures.

For +5 Extra Credit: Create your collage with diagonal symmetry

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

Comments are important here! Please include comments at the top of your class definition:

HW3: Create a dance, complete with music

Using Sampled Sounds and the Turtles, create a musical dance. Play music (sounds at least?) while the turtles move in patterns.

Your piece must last at least 10 seconds.

You must have at least five turtles. They can drop pictures, they can leave trails (or not), they can spin slowly, whatever you want them to do. Your turtles must move.

New!You can have your turtles draw on a World and intersperse sampled sounds using the blockingPlay() method on the Sound sample, or you can have the turtles draw on a Picture and use FrameSequence to play it while you use the regular play() method on a sound sample. Either approach will work.

You must have at least four different sounds.

There must be some interweaving between turtle motion and sounds. In other words, you can't move the five turtles a little, then play 10 seconds of music.

Implement your dance and sounds in a TurtleDance class in a main method.

EXTRA CREDIT: Use MIDI (JMusic) rather than sampled sounds for an additional 5 points extra credit. Look up the Play object in the JMusic docs. Play.midi(score,false) will play a score in the background (false keeps it from quitting Java after playing). Play.waitcycle(score) will block (wait) anything else from happening until the score is done playing – essentially, letting you block like blockingPlay.

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 classes.)

You must use weave and either of the repeats A TOTAL of FIVE 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 pattern. That would be five. Or do one Repeat to create a basic tempo, then four weaves to bring in other motifs.

You must use at least four unique riffs from SongPhrase. (It's okay for you to make all four of them yourself.)

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. It does not need to autoplay!

You will create a class (with some cunning name like MyWovenSong) with a main that will assemble your song, then open it with showFromMeOn (or show–whatever you need to do open up the notation View on your masterpiece). 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 REMOVEDst Manipulations

DUE DATE: Wed Feb. 28

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 (where firstpicturnodeinlist is a node, not actually a picture):

Note: oldelement or findelement will never be equal to the firstnodeinlist

firstnodeinlist.findAndReplaceRepeat(oldelement,newelement,n) Find oldelement (it's a node, not a picture, so you can look for an exact match), remove oldelement from the list, and then insert at oldelement's place n copies of the node newelement.

firstnodeinlist.replaceWithModification(findelement,int type) Find the node findelement (a node, not a picture, so you can do an exact match), then replace it with a node containing a modified picture of the picture in findelement. The "type" indicates the kind of modification. If 1, negate the picture. If 2, mirrorHorizontal. If 3, mirrorVertical. If 4, sunset. If anything else, insert grayscale.

firstnodeinlist.replaceWithModifications(findelement,double[] types) Find the node findelement (a node, not a picture, so you can do an exact match), then replace it with nodes containing a modified picture of the picture in findelement. Insert as many nodes as there are entries in the types array. If there are 3 values in the array, insert 3 copies. The value in the types array indicates the kind of modification for that element. If 1, negate the picture. If 2, mirrorHorizontal. If 3, mirrorVertical. If 4, sunset. If anything else, insert grayscale. So, if the array was {1,2,5}, you would insert three copies of the picture in findelement – the first negated, the second mirrored horizontal, and the third grayscaled.

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 using findAndReplaceRepeat, and (c) a third picture after using replaceWithModification, then (d) a final fourth picture after using replaceWithModifications.

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 the sounds to be played during the animation of this tree. (Sounds could be a rest!)

Here's the key part! When you animate your scene (for at least 20 scenes!) and play your sounds, YOU CANNOT MAKE ANY NEW SOUNDS! You must play your sounds out of your list of sounds. In other words, the sounds must be pre-made and assembled in a structure before you start your animation.

You can use and modify any of the data structures that we've described in class. You can create new data structures if you'd like.

You will also need to create a class (call it 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 play the movie with sound.

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

From here on, there are SEVERAL ways to handle the animation.
Here's one:

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

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. Use blockingPlay() instead of play() on your sound to make the processing wait (synchronize) until the sound is done before moving on. (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.) Note: You don't HAVE to use blockingPlay(). You can use a mixture of play() and blockingPlay() to get better response while still maintaining synchrony.

For 5 points extra credit, use both Sound play() and blockingPlay() in your animation play() – but NOTE that you still can't CREATE any new sounds in your animation play() method. All the sounds still have to be in some kind of linked list data structure before you get started.

We also offer up to 10 points extra credit for the animation which goes beyond our expectation.

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 (unless you've changed them), 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.

Build a class named MidiTool that will create a graphical user interface (GUI).

This GUI will have a string input area where the user can type in a sequence of letters. The letters will define a MIDI sequence. Only the letters c,d,e,f,g,a, and b are allowed, presumed all in the third octave. Lowercase is an eighth note, uppercase is a quarter note. So cEdEgC would be c3 eighth, e3 quarter, d3 eighth, e3 quarter, g3 eighth, c3 quarter.

There should also be buttons:

MakeNode converts the string into a node.

PlayNode plays the node.

ClearSequence clears the current sequence.

RepeatInSequence takes a number in a text area (3, for example) and repeats the currently made node that number of times onto the end of the sequence.

WeaveInSequence weaves the currently made node into the sequence every-other node onto the end.

PlaySequence plays the sequence.

Extra Credit 5 pts: Create a SaveSequence button that saves the sequence into a MIDI file.

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

With your name and your partner's name, GT-email addresses

Explaining what you're doing

Each method has a comment explaining itself

Each SECTION of the code, explains itself. For example, "Here's the panel with the buttons" and "Here's the button that does the weaving."

Variable and method names should be clear and understandable.

Turn in to WebCT: (Only one of you need to submit HW, but don't forget to put your partner's name and GT-email address in your comment.)

Using the Simulation Package, enhance the disease simulation. It's a much more fiendish disease now.

People, once infected (come within 10 steps of an infected person), don't turn red for two days – though they do spread the disease. There is a .05 possibility that an infected person NEVER becomes red – but does spread the disease. Call those the "Typhoid Mary" carriers.

Healthy people, if they get within 20 steps of a VISIBLY infected person (someone red), turn away. But, of course, some people are not visibly carrying the disease, but are infected.

After 5 days of becoming infected, 25% of the people die. Their bodies remain infected and spreading the disease, but they are red so that people can tell to avoid them. The rest of the infected people become non-red at day 6 and become un-infected at day 7. (Yes, there is one day at the end when they are not visibly infected, but they are still infected.)

Students are to implement these rules and to note the average number of people infected (normal size world, start with 100 people and one infected) and the average number dead over three runs.

The goal is then increase the number that survive and decrease the number of infected. Students are to implement TWO of the below public health policies. They are to implement one of the policies, try out three runs and compute the average infected and dead, then implement the second policy and compute the average infected and dead. The students are to produce a Word document with graphs of the number of healthy, infected, and dead people for each of the 100 (Updated from 30 days, you'll get better analysis if you do 100 days) days of each run. The Word document should have 3 graphs for the original rules, then 3 graphs after the first policy implementation and a description of what happened (including average counts of diseased and dead) and why, then 3 graphs after both policies are implemented with a description of what happened
with counts and why.

POLICIES:

Reduce mobility of the sick: When someone becomes visibly infected (red), their speed drops in half.

Reduce mobility of the healthy: Decrease from the start the speed of all people (so they don't bump into the infected as much).

Voluntary quarantine of the sick: When someone is visibly infected, at the beginning of each step, they turn to face (640,480). That way, sick people will tend to move toward the lower right.

Voluntary segregation of the sick and healthy. Visibly infected people turn to face 640,480, and healthy (or presumably healthy – those that are non-red) people turn to face 0,0.

Mandatory quarantine of the sick: At the beginning of the step for visibly infected, they MOVE to 640,480. They can move some from there, but they always go back to their quarantine spot.

Mandatory quarantine of the sick and healthy: All visibly infected move to 640,480, and all visibly healthy people move to 0,0.

Removal of the Dead (the "Holy Grail – bring out your dead!" policy):

All dead bodies immediately go to (640,0). (Presume that people in bioprotection suits are moving the dead without becoming infected themselves.)

Scarce Vaccine (the Chosen Few policy): 5 people (probably national leaders or doctors or police) are given vaccines when first created. They never become infected.

The Paranoid Policy: Everyone stays away from everyone else.

Turn in to WebCT:

Your Agent and Simulation subclasses including your Simulation class if you changed it. Turn in ONE scenario. The TA doesn'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.

CHANGE TO ASSIGNMENT

Please run your simulation for 100 time steps, not just 50. From the runs that I'm seeing, 50 time steps is too early in the simulation, and there seems to be a critical mass a little after 50. You are welcome to change Simulation run() that lets you run for 100.

HW9: Extra Credit

HW9 is an individual assignment, but it is dependent on a working HW8. You will once again be using the Simulation Package and your enhanced disease simulation.

Students are to take their completed HW8 and replace the turtle with character images. There must be:

3 different types of people – they can be different genders, different looks, etc.

a difference between healthy people and sick people (but not all people show the sickness, stick to the criteria in HW8)

That means that that each of the three different types must have a different look.

There must be 3 different positions of each type of people – facing left, facing right, moving left, moving right. You must rotate among these positions, perhaps with a probability of 0.3 of changing position with each time step.

That's 3 positions x 3 types x 2 (sick or healthy) = 18 images that you need to have for the living people.

Dead people should look different from healthy or sick people

This homework will be worth 1-3% on your final grade–it will be graded out of 100, then added in to your overall homework grade.