CS1026a: Assignment 3


Category: You will Instantly receive a download link for .zip solution file upon Payment


5/5 - (3 votes)

As we saw in Lab 7, a movie is made up of a series of images. A digital effect often seen in videos,
presentations and slide shows is called cross fading, or transitioning from one picture to another by
having a number of intermediate pictures which are a mix of the two, progressively using less of the
start picture and more of the end picture. In this assignment you will write a picture manipulation
method that enables you to create pictures that are a mix of two images, and then use this method to
create a movie that shows a cross fade from one picture to another.
Part A:
The first part of the assignment will be to create a picture manipulation method to add to the Picture
class: crossFade. Further detail can be found below, but let’s introduce the algorithm first for cross
You will have a startingPicture, and a colour, both of which you can pick. To create the a sequence of
pictures that cross fade – startingPicture, p1, p2, p3, endingPicture – we will need to create and
modify p1,p2 and p3 pixel by pixel using an equation.
This means we need to write a picture manipulation method that will take a picture make each pixel a
mixture of the start picture’s colour at that pixel and a certain proportion of the ending picture’s colour
at that pixel. We are going to calculate the red, green and blue values for each pixel as being
somewhere between the startingPicture pixel values, and the endingPicture’s.
For each pixel of the fading pictures, we compute its red, green and blue values individually using the
following formula for each colour (example here shown for red):
redValue = startRed + (endRed – startRed) * percentEndPic
where percentEndPic is the percentage (expressed as a decimal proportion between 0 and 1; 90% =
0.9) of the end picture.
So, for example, to compute the red value of a pixel that is halfway to the endingPicture, or 50%, and if
the starting red value of that pixel was 100, and the end value was 200, the formula would be:
redValue = 100 +(200 – 100) * 0.50 (which is 150)
For Part A of the assignment, you will write a method in the Picture class that forms an intermediate
picture in the fade process. The methods will use the picture parameter to modify “this” picture to be a
stage in the fade out / fade in process.
Functional Specifications for Part A
1. You are to write a method crossFade and add it to the Picture class. It will have the header
public void crossFade(Picture startPicture, Picture endPicture,
double percentEndPic)
• startPicture : the starting picture
• endPicture : the end picture
• percentEndPic : the proportion of the end picture to use
crossFade() will be invoked on a Picture object that is the “target” picture, that is, the picture
that represents the proportional mix of the start and end pictures. The method will calculate the picture
for the given proportion by setting the red, green, and blue values for the pixels in this picture
according to the above formula, pixel by pixel.
Your method should be written so that it will not crash if the startPicture, endPicture and “this” image
are of different sizes. We will test this with our own selected pictures, as long as no red text appears
and the program exits normally, you will not be docked marks.
3. You will write a class TestFading (in TestFading.java) that consists of a main method that tests
the crossFade() method. It must contain the following:
i. Get a starting picture and an ending picture from the working directory ( see note below).
The images will need to be the same size, like the following sets of pictures are the same
size: {flower1.jpg, flower2.jpg}, {whiteFlower.jpg, yellowFlowers.jpg, rose.jpg},
{swan.jpg, twoSwans.jpg}, or you can use your own pictures that are the same size.
ii. Create 3 intermediate stages of a crossFade using the method you wrote and the starting and
ending picture you got from the user.
iii. Display the images. You should end up with a total of 5 pictures on the screen from this
test: the starting picture, the 3 intermediate faded pictures, and the ending picture. You
should be able to move them around on the screen using the mouse so that all can be
Note: The working directory – Use files without FileChooser
The working directory is what programmers call the folder (directory) where the program is being run.
In Dr. Java, the working directory is the same as the location of the “.class” file that you are running.
You can see the working directory listed at the top of the interactions pane when you hit “Run” in Dr.
To use files that are saved in the working directory in your program, you simply list their name and the
program will know to look in the working directory for that file. If it is not there, you will get an error
when you try to load the Picture file.
For example, if I had the files for this Part A in the folder, along with two images like this:
I could create a picture object using the following line:
Picture startPic = new Picture(“swan.jpg”);
Part B:
You are going to make a movie that fades from one picture to the next using the method you
created in part A. Just as you did in Lab 7, you will using the FrameSequencer and the
MoviePlayer classes to create the movie.
Functional Specifications for Part B
1. You will create and play your movies in a Java program with the class name FadingMovie that
will be saved in a file named FadingMovie.java. This class will consist primarily of a main method
whose algorithm is given below.
2. The algorithmic specifications for the main method are:
• Get the starting picture and ending picture for the fading, using files from the working
directory. If the starting picture and ending picture are not the same size, print an error message
and do not proceed with the rest of the program. (Use the showInformation() method of
the SimpleOutput class for your error message.)
• Get the number of intermediate stages for the cross fade from the user (using the
SimpleInput class).
• Input the name of the directory in which to store the movie (using the SimpleInput class).
Note: that the directory name that you enter should end with a slash, for example
• Create an array of Picture objects that will hold the sequence of pictures for the fading.
• Store the starting and ending pictures in the array.
• Create intermediate pictures in the array, using a loop. Each new Picture object must also be the
same size as the start/end images.
• Make the intermediate images a steady progression from the start picture to the end picture
using a loop that invokes the crossFade method from Part A on each intermediate picture.
• Create a movie from the array of pictures you have completed using a FrameSequencer
object (as you did in Lab 7).
• Play the movie using a MoviePlayer object and playMovie().
3. Frames will be determined by numStages input by user.
4. Images from the following sets of pictures are the same size: {flower1.jpg, flower2.jpg},
{whiteFlower.jpg, yellowFlowers.jpg, rose.jpg}, {swan.jpg, twoSwans.jpg}, or you can use your
own pictures that are the same size.
Caution: If you use your own pictures, you may run out of memory space (RAM) if they are
too large. Also, when creating a movie with many frames, it will create a picture in the
directory given for each one, which could eat up a lot of disk space. Try your program on
small pictures first, such as those suggested for Part A.
Non-functional Specifications:
• Include a comment at the top of your file which includes:
// CS1026B Assignment 3
// Your name
// A brief description of what this program does
• Also Include brief comments (lines beginning with two forward slashes //) in your code that
explain the major steps of the program. Ex:
// Get pictures and parameters from user
• Include brief comments above each method you write about what the method does.
• Use named constants as appropriate.
• Use Java conventions and good Java programming techniques, for example:
o Meaningful variable names
o Conventions for naming variables and constants
o Readability: indentation, white space, consistency
• Assignments are to be done individually and must be your own work. Software may be used to
detect cheating.
What to Hand In:
1. Picture.java (with your crossFade() method added), TestFading.java, FadingMovie.java
2. The image files for the starting picture and the ending picture for your fading movie, even if they
are from the mediasources.
What You Will Be Marked On:
1. Functional specifications:
ü Are the required methods written according to specifications?
ü Do they work as specified? Pay attention to details!
ü Are they called as specified?
2. Non-functional specifications: as described above
3. Assignment submission: Through the assignment submission form in OWL under the tab: