The purpose of this assignment is to introduce you to programming with loops, in the context of music.
Write a program MusicLoop.java
that takes two command-line arguments
(a string filename of a .wav
file and a positive integer)
and plays the .wav
file in a music loop the specified number of times.
Here are some sample executions:
~/Desktop/loops> javac-introcs MusicLoop.java ~/Desktop/loops> java-introcs MusicLoop StompStompClap.wav 25 ~/Desktop/loops> java-introcs MusicLoop AmenBreak.wav 10 ~/Desktop/loops> java-introcs MusicLoop Fresh.wav 50 ~/Desktop/loops> java-introcs MusicLoop Heartbeat.wav 60 ~/Desktop/loops> java-introcs MusicLoop Ringtones/Marimba6.wav 6
Optional: Create and submit a WAV file MyMusicLoop.wav
that, when looped,
produces an interesting effect (such as a drum loop, ultrasound, bird chirp).
You can do this either via a personal recording or by dowloading a file
and cropping it.
Write a program MajorScale.java
that takes two command-line
arguments (an integer MIDI note number and a string instrument name)
and plays a major scale starting at the specified root note.
To play a note, use the corresponding WAV file in the directory specified
by the instrument name. For example,
piano/piano69.wav is concert A on a piano
and
opera/opera60.wav is middle C from an
opera singer.
For example, here are the notes in a C major scale, starting at middle C (60):
Here are the notes in an A major scale, starting at concert A (69):
You must use a single for
loop in this program.
Note that the MIDI note number increases by 2 in each step, except
after the 3rd and 7th notes, in which case it goes up by 1.
Here are some sample executions:
~/Desktop/loops> javac-introcs MajorScale.java ~/Desktop/loops> java-introcs MajorScale 60 piano ~/Desktop/loops> java-introcs MajorScale 69 piano ~/Desktop/loops> java-introcs MajorScale 45 opera ~/Desktop/loops> java-introcs MajorScale 60 solfege
Here are the notes in a 2-octave C major scale, starting at middle C (60), ascending and descending:
Write a program DeluxeMajorScale.java
that takes three command-line
arguments (an integer MIDI note number, an integer number of octaves,
and a string instrument name)
and plays a major scale starting at the specified root note,
for the specified number of octaves, both ascending and descending.
Note that a \(k\)-octave major scale has \(7k + 1\) notes ascending
and \(7k + 1\) notes descending; moreover, each note is played exactly twice
(the \(i\)th and (\(14k + 3 - i\))th notes are the same).
~/Desktop/loops> javac-introcs DeluxeMajorScale.java ~/Desktop/loops> java-introcs DeluxeMajorScale 69 1 piano ~/Desktop/loops> java-introcs DeluxeMajorScale 60 2 piano ~/Desktop/loops> java-introcs DeluxeMajorScale 50 2 mbira ~/Desktop/loops> java-introcs DeluxeMajorScale 36 3 guitar
SepiaFilter.java
to apply a sepia filter to an image (using StdPicture
).
A sepia filter adds a warm reddish-brown tone to the image, giving it a vintage look.
Sepia filters are popular on Instagram, VSCO, Facetime, and Photoshop.
“Nassau Hall facing Cannon Green” by Nick Barberio sepia filter
To apply a sepia filter to an image, consider each pixel one at a time.
\( \begin{align} r' &\;=\; 0.393r \,+\, 0.769g \,+\, 0.189b \\ g' &\;=\; 0.349r \,+\, 0.686g \,+\, 0.168b \\ b' &\;=\; 0.272r \,+\, 0.534g \,+\, 0.131b \\ \end{align} \)
Write a program SepiaFilter.java
that takes the name of an image file
as a command-line argument, applies a sepia filter to that image, and
displays the results in a window.
Use
StdPicture
to read, modify, and display the picture.
Here are some sample executions for the images NassauHall.jpg and JohnsonArch.jpg:
~/Desktop/loops> javac-introcs SepiaFilter.java ~/Desktop/loops> java-introcs SepiaFilter NassauHall.jpg ~/Desktop/loops> java-introcs SepiaFilter JohnsonArch.jpg
Take a photo of a building, archway, gate, or other structure on campus
and apply the sepia filter to that image.
Submit a JPG file MyPhoto.jpg
of the source image.
Submission.
Submit
MusicLoop.java
,
MyLoop.wav
,
MajorScale.java
,
DeluxeMajorScale.java
,
SepiaFilter.java
and
MyPhoto.jpg
.
Also submit a readme.txt file and answer the questions.
You may not call library functions except those in the java.lang
(such as Integer.parseInt()
and Math.random()
).
Do not use Java features that have not yet been introduced in the course.
Grading.
File | Points |
---|---|
MusicLoop.java | 7 |
MajorScale.java | 7 |
DeluxeMajorScale.java | 8 |
SepiaFilter.java | 8 |
MyPhoto.jpg | 5 |
readme.txt | 5 |
Total | 40 |