Hello Friends.
I am new to Java, I am taking my first class. I currently have an assignment
for homework, I am not asking anyone to do it for me, but I am asking for help.
I am currently playing some jpgs, to make it look like a small movie. The
assignment asks for me to draw a line that moves across the pictures, and as it
moves, the image should be turning to a grayscale. I have made the line, and it
moves across the frames, I have also made the grayscale and it also moves
across the picture, the problem is that they are not synced, the line goes much
faster then the grayscale. Does anyone have any suggestions as what to do? Any
help is appreciated.
I am attaching the .java file (remember I am a newbie, so the code may not be
that good) hopefully someone will have suggestions.
Thank you for your time.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---
package cs152;
import java.awt.Color;
import java.awt.Graphics;
import bookClasses.Picture;
import bookClasses.Pixel;
public class MoviePlayer {
public static void main(String[] args) {
//Open the picture and show it 1280x544
Picture p = new Picture ( "/home/ramon/Desktop/eclipse/mediasources/h3/h3 001.jpg" );
p.show ( );
//Define the number of frames
int numFrames = 492;
//Start a timer (used to calculate the frame rate), and iterate over all the frames we have
double startTime = System.currentTimeMillis ( );
for ( int i = 1; i <= numFrames; i++ ) {
//Build the new file name
String fileName = "/home/ramon/Desktop/eclipse/mediasources/h3/h3 ";
if ( i < 10 )
fileName += "00" + i;
else if ( i < 100 ) {
fileName += "0" + i;
} else if ( i < 1000 ) {
fileName += i;
}
fileName += ".jpg";
//Load the next image in sequence
p.loadImage ( fileName );
Graphics g = p.getGraphics ( );
//Add some text to each frame
g.drawString ( fileName, p.getWidth ( ) / 2, p.getHeight ( ) - 5 );
//Call in the changes to picture
g.create();
//Create the line
// if (p.getHeight()/2 > p.getHeight())
// {
// for (i = 0; i < p.getHeight(); i = i * i++ );
// }
// else
// {
// g.drawLine(-p.getHeight()*480, i++ * 2 , 640, i++ * 2);
//g.drawLine(p.getWidth()/2 + i, 0, p.getWidth()/2-i, p.getHeight());
// }
//Get the pixels and then change color to grayscale
Pixel[] pixels = p.getPixels();
for (int i1 = 0; i1 < pixels.length / pixels.length + Math.pow(i, 2.15); i1++)
{
Pixel pix = pixels[i1];
int red = pix.getRed();
pix.setGreen( red );
pix.setBlue( red );
}
g.drawLine(-p.getHeight()*544, i++ , 1280, i++ );
//Draw the ball for the "bouncing"
// for (int x = 0; x < p.getWidth ( ) - 100; x = x + 3 ){
// //g.drawOval(p.getHeight()/2, 0, 100, 100);
// g.drawOval(x, 0, 100, 100);
// g.setColor(Color.RED);
// }
//Posible way to change grayscale
//p.grayscaleWithLuminance();
//Update the picture
p.repaint ( );
//Sleep for x milliseconds
try {
Thread.sleep ( 20 );
} catch ( InterruptedException e ) {
}
}
double endTime = System.currentTimeMillis ( );
//Print out the frame rate after
System.out.println ( "FrameRate = "
+ ( numFrames / ( ( endTime - startTime ) / 1000.0 ) ) );
}
}