Due Date:
Monday, Oct 18 at midnight. Note, this assignment will graded (10 pts).
These assignments are tentative: audio files.
The main goals of this lab are to:
Program 1 is a very simple example of an animated ball. The ball drops down vertically. When it reaches the bottom, it is reset to be at the top again. Run the code to see what it does.
Program 1: Single Ball Drop | |
|
![]() |
The above program would be a lot more interesting if we could have a lot of
balls all moving independently. One way to do this for would be to declare multiple variables:
As you might expect, this can get a bit tedious if you have a lot of balls, e.g. 100 balls.
Arrays are data structures used in mose programming languages that allow one to create
lists of variables of the same type. Below is an example that uses an array to store
the y location of 20 balls. Run the code to see what it does.
In class, we will go over the syntax for creating, setting, and
accessing arrays.
int y1, y2, y3, y4;
int x1, x2, x3, x4;
Program 2: Multiple Ball Drop | |
|
![]() |
One can modify the above program to include arrays for storing other characteristics for each ball such as the color, the x value, the dx and dy etc. For example, below is the bouncing ball program from a previous lab but with 10 balls.
Program 3: Multiple Ball Bounce | |
|
![]() |
In the above program, the balls change direction when they hit the wall. This is an example of an event-response situation. An event (hitting the wall) triggers a response (change in direction). The event could be any number of things such as a ball hitting another ball or the user clicking the mouse. The events could also be any number of things such as changing the ball's color or size. One could also have a sound play. The assignment you will turn in for this lab will require that you use sounds as the response to some action.
An example of an event triggered by the mouse would be having a ball's color change when the user clicks on it. To see how this works, add the following function to the bottom of the above program.
Program 3a: Mouse Event Code for Multiple Ball Bounce |
|
Program 4: Simple Sound Example | |
|
![]() |
As was the case with the video, you will need to add a new tab to your sketch program (e.g. called Sound) and copy in the code below. Note that you need to include this in any program where you use sound. You should not have to make any changes to it. The above program initializes the sound functionality using the function call soundSetup() which needs to be in the setUp function. To play the sound, the uses the command mySound[n].play(0). This will be explained more in class.
Program 4a: Sound Code (add as extra tab) |
|
Run the program. When you click in the window, a different sound should play depending on the y value of the mouse click. An ellipse appears where you click whose color is linked to the choice of sound. We will go over the code in class.
Program 5 is another example using sound. It is the same as Program 1 but with sound added. The event that triggers the sound is the ball reaching the middle or bottom of the window. The response is one of two different sounds.
Program 5: Ball Drop with Sound Requires the sound code (Program 4a) and the audio files in the sketch folder. |
|
In this lab, you will be given a set of sounds created by students in Musc 121. The sounds vary in pitch, register, and synthesizer name. You do not need to use all of the sounds but you should use at least 5 or 6. As described above, you will need to place the sounds in your sketch folder in a subfolder called audio (if you don't place them in exactly this location, you will get a NullPointer error when you try to run the code).
The sounds are to be used as a response to some event. The event might be a user action (e.g mouse click or key press) or it could be based on something that is happening during the animation going on in the window (e.g. ball hitting a wall).
Recommendation: Limit the frequency of events that trigger the sound. If events occur too frequently, the sounds will run into each other.
When you are done, export your program to a Java Applet by going to the Processing menu and choosing "export". This will create a new subfolder in your sketch folder called "applet". You will need to copy your audio folder into the applet folder. You can test the applet by double clicking on the file called index.html that is located in the applet folder. When you do this, a browser should open up with your applet running in it. We have had problems on some computers with the applets not running. If yours doesn't run on your computer, it may run on a different computer. If you just can't get it to run anywhere, don't worry about it.
This lab will be graded based on a 10 point scale. As in previous labs, zip together your entire sketch folder (with applet and sounds) and add as an attachment in WISE. Please don't forget to follow the steps below for cleaning up your code. Points will be taken off if you do not do this. Clean, well commented, and easy to understand code is very important.
Files: You should be turning in one Processing Sketch. The sketch folder should contain
- the *.pde files (including Sound.pde)
- the audio files
- A single image snapshot. See lab 4 for how to take the snapshot.
Cleaning up the Code: Make sure that you have cleaned up the Processing code as follows:
- Delete any unused sections of code.
- At the top of the code, add comments containing your name, the lab number, the course number, and a one sentence description of what the code does. Add additional comments, if ncessary, so that someone else looking at the code can follow what the code does. This will become more useful as your programs get longer and more complex.
- (THIS IS REALLY IMPORTANT) Run the Auto-format command by going to the Processing menu: Tools→AutoFormat. You may have to do some additional formatting by hand.
Zipping: When you are done doing all of the above, zip together your sketch folder into a single zip file.
By midnight of Mon, Oct 18, submit the single zipped file via WISE as an attachment.