LAB 43 – Creating and Modifying Movies (part 2)
Lab Exercises
Topics
Using BlueJ to start a new application
1) Starting BlueJ or DrJava - double-click icon.
2) Add bookClasses to libraries through preferences
3) Creating a new project - select New Project from the Project menu and save the project as Lab42.
4) Click on New Class and type Movie as the class name and select Class as the class type
5) Right-click on the Movie class and select Open Editor
6) Replace the code generated by BlueJ with the following; update the comments.
public class movie
{
public static void main(String[] args)
{
MovieMaker movieMaker = new MovieMaker();
String dir = "c:/temp/movies/sunset/";
movieMaker.makeSunsetMovie(dir);
}
}
7) Click on New Class and type MovieMaker as the class name and select Class as the class type
8) Right-click on the MovieMaker class and select Open Editor
9) Replace the code generated by BlueJ with the following; update the comments
public
class MovieMaker
{
public void makeSunsetMovie(String directory)
{
String fName = FileChooser.pickAFile();// choose “beach-smaller.jpg"
Picture beachP = new Picture(fName);
int framesPerSec = 30;
FrameSequencer frameSequencer = new FrameSequencer(directory);
frameSequencer.show();
// loop through the first second
for (int i = 0; i < framesPerSec; i++)
{
makeSunset(beachP , 0.95);
// add frame to sequencer
frameSequencer.addFrame(beachP);
}
// play the movie
frameSequencer.play(framesPerSec);
}
/** method that reduces the amount of blue & green to simulate a sunset
*
* @param pic – picture to manipulate
* @param reduction – amount to multiply original values by
*/
public void makeSunset(Picture pic, double reduction)
{
Pixel[] pixelArray = pic.getPixels();
Pixel pixel = null;
int value = 0;
int i = 0;
// loop through all the pixels
while (i < pixelArray.length)
{
// get the current pixel
pixel = pixelArray[i];
// change the blue value
value = pixel.getBlue();
pixel.setBlue((int) (value * reduction));
// change the green value
value = pixel.getGreen();
pixel.setGreen((int) (value * reduction));
// increment the index
i++;
}
}
}
10) To run the program, right-click on the Movie class and select and select void main (String[] arguments)
11) Modify the MovieMaker class to either a) use edge detection or sepia-tint (Lab 18) to make a picture disappear or change, or b) use blend (pg. 156) to morph one picture into another, or c) any of the other transformation from chapters 4,5, or 6 .
12) Compile and run the modified program.
QUESTIONS: Submit Movie.java and MovieMaker.java to the DropBox in WebCT.