Task:
A digital effect often seen in videos, presentations and commercials is fading out and also fading in. To achieve a fade out, starting with a digital image and a colour to fade out to, we slowly turn the image into an image made up of pixels that are all the that colour by constructing a number of intermediate images. Each of these intermediate images is constructed from the pixel in the initial image we start with, and a proportion of the end colour. The construction is done systematically, so that when looking at a sequence of pictures, startingPicture, p1, p2, p3, endingPicture, it appears that each successive intermediate picture p1, p2 and p3 becomes more and more like endingPicture, which for the fade out, is a solid colour. The more intermediate pictures we create, the smoother the fade out. A similar process is used to fade in, where we start with an image made up entirely of a start colour, and slowly progress to the pixel colours found in our ending image.
Part A:The first part of the assignment will be to create two methods to add to the Picture class: fadeOut and fadeIn. Further detail can be found below, but lets introduce the algorithm first for fading out. The algorithm for fading in will be very similar. You will have a startingPicture, and a colour, both of which you can pick. To create the a sequence of pictures that fade out: startingPicture, p1, p2, p3, endingPicture, where endingPicture is a solid colour, we will need to create and modify p1,p2,p3 and endingPicture pixel by pixel using an equation. We are going to calculate the red, green and blue values for each pixel as being somewhere between the startingPicture pixel values, and the solid colour. 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)/numStages) * k where numStages is the total number of stages (ex 4; p1,p2,p3 and endingPicture for the example above) to be used in the fade out, and k is the kth picture. So, for example, to compute the red value of a pixel in p2, the value of k would be 2. If the starting red value of that pixel was 100, and the end value was 200, the formula would be: redValue of pixel = 100 + ((200 – 100)/4) * 2 This formula must be used three times on every pixel in order to get the red, green and blue values for the pixel. This idea can be extended for any number of intermediate pictures. If we wanted 7 stages instead of 3, then k would range from 1 to 7, and we would have divided by 7 in the formula. In general, the formula for each colour is: colourValue = startValue + ((endValue – startValue)/(numStages )) * k For Part A of the assignment, you will write TWO methods in the Picture class that form an intermediate picture in the fade out and fade in sequence respectively, as specified below. 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 fadeOut and add it to the Picture class. It will have the header public void fadeOut(Picture startPicture, Color fadeTo, int numStages, int k)
• startPicture : the starting picture
• fadeTo : the solid colour to be used in the final image
• numStages : the total number of stages in the fade out process, including the final image
• k : the current stage in the fading process
(will be a number between 1 and numStages inclusive)
fadeOut() will be invoked on a Picture object that is the “target” picture, that is, the picture that represents the kth stage in fading from the starting picture to the ending colour. The method will form the picture for the current stage (ie stage k) 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 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.
2. You are to write a method fadeIn and add it to the Picture class. It will have the header public void fadeIn(Picture endPicture, Color fadeFrom, int numStages, int k)
• endPicture : the ending picture
• fadeFrom : the solid colour to be used in the first image
• numStages : the total number of stages in the fade in process, including the first image
• k : the current stage in the fading process
(will be a number between 0 and numStages-1 inclusive)
fadeIn() will be invoked on a Picture object that is the “target” picture, that is, the picture that represents the kth stage in fading from the starting colour to the ending picture. The method will form the picture for the current stage (ie stage k) by setting the red, green, and blue values for the pixels in this picture according to the above formula (note that the starting and ending values will not be from the same sources), pixel by pixel. Your method should be written so that it will not crash if the 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 primarily of a main method that tests fadeOut() and fadeIn() for correctness. It must contain the following tests:
i. Get a picture using FileChooser. form 4 stages of the fade out process and display them, along with the starting picture. (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 which is a solid colour. You should be able to move them around on the screen using the mouse so that all can be displayed.)
ii. Perform the same steps for fadeIn.
Did I scare you guys away?