Detta är en gammal java-applet-klassiker. Möjligen är min lösning lite annorlunda.
Men visst är det vackert!
Klassen Mirror
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
public class Mirror extends Applet implements Runnable {
private Image bild;
private BufferedImage buff;
private Graphics2D gr;
double f = 0.7;
double h = 3.0;
private int width, height = 0;
private Thread t = null;
public void init() {
buff = new BufferedImage(256, 500, BufferedImage.TYPE_INT_ARGB);
gr = buff.createGraphics();
bild = this.getImage(this.getDocumentBase(), "frogg.jpg");
MediaTracker tr = new MediaTracker(this);
try {
tr.addImage(bild, 0);
tr.waitForAll();
width = bild.getWidth(this);
height = bild.getHeight(this);
} catch (Exception error) {
}
}
public void paint(Graphics page) {
gr.setPaint(new Color(0, 0, 0));
gr.fillRect(0, 0, 256, 500);
gr.drawImage(bild, 0, 0, this);
int bottom = (height * 2) - 1;
for (int i = 0; i < height; i++) {
gr.copyArea(0, i, 256, 1, (int) h, bottom);
bottom -= 2;
h += f;
if (h > 4.0 || h <= 1)
f *= -1;
}
page.drawImage(buff, -3, 0, this);
}
public void update(Graphics page) {
paint(page);
}
public void start() {
if (t == null) {
t = new Thread(this);
t.start();
}
}
public void run() {
while (t != null) {
repaint();
try {
Thread.sleep(0);
} catch (InterruptedException error) {
}
;
}
}
public void stop() {
t = null;
}
}