home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.image.MemoryImageSource;
- import java.awt.image.PixelGrabber;
-
- class WobbleCanvas extends Canvas {
- Image sourceImage;
- Image destImage;
- int widthImage;
- int heightImage;
- MediaTracker tracker;
- int[] sourcePixels;
- int[] destPixels;
- double RadiansPerDegree = (Math.PI / 180D);
- private int delta;
- private double amplitude = (double)100.0F;
- private int baseline;
- private MemoryImageSource producer;
- private int color;
-
- public WobbleCanvas(Image image, int colorValue) {
- this.sourceImage = image;
- this.color = colorValue;
- this.tracker = new MediaTracker(this);
- this.tracker.addImage(image, 0);
- ((Component)this).reshape(0, 0, 500, 100);
- }
-
- protected void finalize() throws Throwable {
- this.tracker = null;
- this.destImage = null;
- this.destPixels = null;
- this.sourcePixels = null;
- super.finalize();
- }
-
- public void moveDelta(int direction) {
- this.delta += direction;
- }
-
- public void setAmplitude(double value) {
- this.amplitude = value;
- }
-
- public void setBaseline(int value) {
- this.baseline = value;
- }
-
- public void setColor(int value) {
- this.color = value;
- }
-
- protected void HorizLine(int Offset, int width) {
- int SH = 16;
- int add = (this.widthImage << SH) / width;
- int srcOffset;
- int destOffset;
- if (width > this.widthImage) {
- srcOffset = Offset + (width >> 1) - (this.widthImage >> 1) << SH;
- destOffset = Offset;
- width = this.widthImage;
- } else {
- srcOffset = Offset << SH;
- destOffset = Offset + (this.widthImage >> 1) - (width >> 1);
- }
-
- for(int x = 0; x < width; ++x) {
- this.destPixels[destOffset] = this.sourcePixels[srcOffset >>> SH];
- ++destOffset;
- srcOffset += add;
- }
-
- }
-
- public void paintScreen() {
- int y = 0;
-
- for(int Offset = 0; y < this.heightImage; Offset += this.widthImage) {
- int value = (int)(Math.sin((double)(y + this.delta) * this.RadiansPerDegree) * this.amplitude);
- this.HorizLine(Offset, value + this.widthImage + this.baseline);
- ++y;
- }
-
- }
-
- public void update(Graphics g) {
- if ((this.tracker.statusAll(true) & 8) == 0) {
- g.drawString("(c)1996 MYSTiC BYTES. http://www.mystic.de - Loading...", 0, 50);
- } else {
- if (this.destPixels == null) {
- this.widthImage = this.sourceImage.getWidth(this);
- this.heightImage = this.sourceImage.getHeight(this);
- ((Component)this).reshape(0, 0, this.widthImage, this.heightImage);
- this.sourcePixels = new int[this.widthImage * this.heightImage];
- PixelGrabber pg = new PixelGrabber(this.sourceImage, 0, 0, this.widthImage, this.heightImage, this.sourcePixels, 0, this.widthImage);
-
- try {
- pg.grabPixels();
- } catch (InterruptedException var4) {
- System.err.println("interrupted waiting for pixels!");
- return;
- }
-
- this.destPixels = new int[this.widthImage * this.heightImage];
-
- for(int index = 0; index < this.widthImage * this.heightImage; ++index) {
- this.destPixels[index] = -16777216 + this.color;
- }
-
- this.producer = new MemoryImageSource(this.widthImage, this.heightImage, this.destPixels, 0, this.widthImage);
- }
-
- this.paintScreen();
- this.destImage = ((Component)this).createImage(this.producer);
- g.drawImage(this.destImage, 0, 0, this);
- }
- }
-
- public void paint(Graphics g) {
- this.update(g);
- }
- }
-