// Example using a FOR loop to chromakey a sprite onto a background multiple times // to give the appearnce of motion. // // Jay Summet - Georgia Tech // Released to the public domain: Aug 2009 // import java.awt.Color; public class PictureAnimationExample { public static void main( String [] args ) { // Ask the user to pick a background. "Beach.jpg" or "Jungle.jpg" are good choices String myBackground = FileChooser.pickAFile(); // p2Show is shown on-screen. p is used to store the unmodified background // and is copied (composed) on top of p2Show every time so that the sprite // will have a fresh background to be chromakeyed onto. Picture p2show = new Picture(myBackground); Picture p = new Picture(myBackground); // The following line will only work correctly if you have ALREADY set the // default Media Path using a command such as: // FileChooser.setMediaPath( FileChooser.pickADirectory() ); Picture sprite = new Picture("mRight.jpg"); // Another bluescreened background to try is dogSide.jpg // Show the background. p2show.show(); // Load a pixel at 0,0 from the sprite picture and get it's color. // Use that color as the blue screen value. Pixel myPixel = sprite.getPixel(0,0); Color myColor = myPixel.getColor(); System.out.println("Color at 0,0 is:" + myColor); int stepSize = p.getWidth() / 10; for(int i = 0; i < p.getWidth(); i = i + stepSize ) { sprite.chromakey( p2show, myColor, 50, i,0); p2show.repaint(); // Compose the unmodified background back onto the drawing window // to get it ready to chromakey the sprite onto a fresh background p.compose(p2show,0,0); } // end for } // End of main } // end of class Example