Applet Code -- Mixing Two Scenes
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.lang.*;
public class Fade extends Applet
{
Graphics sG;
Graphics bG;
Image bI;
Image lincoln, memorial, display;
int lincoln_array[] = new int[48000];
int memorial_array[] = new int[48000];
int display_array[] = new int[48000];
int red, green, blue;
int sw = 0;
Color back = new Color(247, 243, 234);
Color black = new Color(0, 0, 0);
Color slider = new Color(255, 128, 128);
PixelGrabber getmemorial, getlincoln;
double t = 1.0;
int mx, my;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
lincoln = getImage(getCodeBase(), "lincoln.gif");
memorial = getImage(getCodeBase(), "memorial.gif");
display = getImage(getCodeBase(), "memorial.gif");
mx = 215;
drawscreen();
}
public void paint(Graphics g)
{
bG.drawImage(memorial, 0, 0, this);
bG.drawImage(lincoln, 430, 0, this);
bG.drawImage(display, 215, 0, this);
g.drawImage(bI, 0, 0, this);
sG = getGraphics();
}
public void update(Graphics g)
{
drawscreen();
paint(g);
}
public void drawscreen()
{
bG.setColor(back);
bG.fillRect(0, 0, 631, 271);
bG.setColor(slider);
bG.fillRect(mx - 3, 250, 7, 17);
bG.setColor(black);
bG.drawLine(215, 258, 415, 258);
for(int x = 215; x < 416; x = x + 20)
{
bG.drawLine(x, 253, x, 263);
}
}
public boolean mouseDown(Event evt, int px, int py)
{
if(py > 250)
{
mx = java.lang.Math.min(px, 415);
mx = java.lang.Math.max(mx, 215);
t = 1.0 - (mx - 215.0)/200.0;
if (sw == 0)
{
sw = 1;
getmemorial =
new PixelGrabber(
memorial, 0, 0, 200, 240, memorial_array, 0, 200);
getlincoln =
new PixelGrabber(
lincoln, 0, 0, 200, 240, lincoln_array, 0, 200);
try {getmemorial.grabPixels();}
catch(Exception e) {return true;}
try {getlincoln.grabPixels();}
catch(Exception e) {return true;}
}
drawscreen();
for(int i = 0; i < 48000; i = i + 1)
{
blue = (int) java.lang.Math.round(
t * (0xFF & memorial_array[i]) +
(1 - t) * (0xFF & lincoln_array[i]));
green = (int) java.lang.Math.round(
t * (0xFF00 & memorial_array[i]) +
(1 - t) * (0xFF00 & lincoln_array[i]));
green = green & 0xFF00;
red = (int) java.lang.Math.round(
t * (0xFF0000 & memorial_array[i]) +
(1 - t) * (0xFF0000 & lincoln_array[i]));
red = red & 0xFF0000;
display_array[i] = 0xFF000000 | blue | red | green;
}
display =
createImage(
new MemoryImageSource(200, 240, display_array, 0, 200));
bG.drawImage(memorial, 0, 0, this);
bG.drawImage(lincoln, 430, 0, this);
bG.drawImage(display, 215, 0, this);
sG.drawImage(bI, 0, 0, this);
}
return true;
}
}
Copyright c 1995 by
Frank Wattenberg, Department of Mathematics, Montana State University,
Bozeman, MT 59717