home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / CUECARDS.EXE / CueCards.class (.txt) next >
Encoding:
Java Class File  |  1997-03-11  |  5.3 KB  |  197 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7.  
  8. public class CueCards extends Applet implements Runnable {
  9.    static boolean dispCopy;
  10.    Image origImg;
  11.    Image backImg;
  12.    Image animImg;
  13.    // $FF: renamed from: w1 int
  14.    int field_0;
  15.    // $FF: renamed from: h1 int
  16.    int field_1;
  17.    Graphics backG;
  18.    Graphics finG;
  19.    Thread nick;
  20.    int frameNo;
  21.    int frames = 12;
  22.    int period = 50;
  23.    boolean needAnim;
  24.    boolean imLoaded;
  25.    boolean needImage;
  26.    boolean animReady;
  27.    double angle1;
  28.    int imageNo = 1;
  29.    Color backCol;
  30.  
  31.    public void start() {
  32.       if (this.nick == null) {
  33.          this.nick = new Thread(this);
  34.          this.nick.start();
  35.       }
  36.  
  37.    }
  38.  
  39.    public void stop() {
  40.       if (this.nick != null) {
  41.          this.nick.stop();
  42.          this.nick = null;
  43.       }
  44.  
  45.    }
  46.  
  47.    public void loadImage() {
  48.       MediaTracker tracker = new MediaTracker(this);
  49.       String nextImage = ((Applet)this).getParameter("image" + this.imageNo);
  50.       if (nextImage == null) {
  51.          this.imageNo = 1;
  52.          nextImage = ((Applet)this).getParameter("image1");
  53.       }
  54.  
  55.       ++this.imageNo;
  56.       this.imLoaded = false;
  57.       this.origImg = ((Applet)this).getImage(((Applet)this).getDocumentBase(), nextImage);
  58.       tracker.addImage(this.origImg, 0);
  59.  
  60.       try {
  61.          tracker.waitForAll();
  62.       } catch (InterruptedException var5) {
  63.       }
  64.  
  65.       this.field_0 = this.origImg.getWidth(this);
  66.       this.field_1 = this.origImg.getHeight(this);
  67.    }
  68.  
  69.    public void rotateImage(Graphics g, double angle) {
  70.       double twistAngle = angle;
  71.       double quart = (Math.PI / 2D);
  72.       double oct = (Math.PI / 4D);
  73.       if (angle > oct) {
  74.          this.shearY(g, (double)1.0F);
  75.          this.shearX(g, (double)1.0F);
  76.          this.shearY(g, (double)1.0F);
  77.          twistAngle = angle - quart;
  78.       }
  79.  
  80.       this.shearX(g, Math.tan(twistAngle / (double)2.0F));
  81.       this.shearY(g, Math.sin(twistAngle));
  82.       this.shearX(g, Math.tan(twistAngle / (double)2.0F));
  83.    }
  84.  
  85.    public void shearX(Graphics g, double shearing) {
  86.       for(int i = 0; i < this.field_1 << 1; ++i) {
  87.          double l = (double)i * -shearing + (double)this.field_1 * shearing;
  88.          g.copyArea(0, i, this.field_0 * 3 >> 1, 1, (int)l, 0);
  89.          g.drawLine((int)l, i, 0, i);
  90.          g.drawLine((int)l + (this.field_0 * 3 >> 1), i, this.field_0 * 3 >> 1, i);
  91.       }
  92.  
  93.    }
  94.  
  95.    public void run() {
  96.       while(this.nick != null) {
  97.          if (this.needImage) {
  98.             this.needImage = false;
  99.             this.loadImage();
  100.          }
  101.  
  102.          if (this.needAnim) {
  103.             this.needAnim = false;
  104.             this.animReady = false;
  105.             this.createAnim();
  106.          }
  107.  
  108.          ((Component)this).repaint();
  109.          if (this.frameNo < this.frames) {
  110.             if (this.frameNo == this.frames - 1) {
  111.                this.needAnim = true;
  112.             }
  113.  
  114.             ++this.frameNo;
  115.          } else if (this.frameNo >= this.frames) {
  116.             if (this.frameNo == this.frames) {
  117.                this.needImage = true;
  118.             }
  119.  
  120.             if (this.frameNo == (this.frames << 1) - 1) {
  121.                this.frameNo = 0;
  122.             }
  123.  
  124.             ++this.frameNo;
  125.          }
  126.  
  127.          try {
  128.             Thread.sleep(50L);
  129.          } catch (InterruptedException var3) {
  130.          }
  131.       }
  132.  
  133.    }
  134.  
  135.    public void shearY(Graphics g, double shearing) {
  136.       for(int i = 0; i < this.field_0 * 3 >> 1; ++i) {
  137.          double l = (double)i * shearing;
  138.          g.copyArea(i, 0, 1, this.field_1 << 1, 0, (int)l);
  139.          g.drawLine(i, (int)l, i, 0);
  140.          g.drawLine(i, (int)l + (this.field_1 << 1), i, this.field_1 << 1);
  141.       }
  142.  
  143.    }
  144.  
  145.    public void init() {
  146.       if (!dispCopy) {
  147.          System.out.println("cueCards v 1.0 for Java");
  148.          System.out.println("Copyright (c) " + "David Griffiths, 1996. " + "All rights reserved.");
  149.          System.out.println("For more information visit " + "http://www.demon.co.uk/davidg,");
  150.          System.out.println("or contact: " + "dgriffiths@msn.com");
  151.          dispCopy = true;
  152.       }
  153.  
  154.       this.backCol = new Color(Integer.parseInt(((Applet)this).getParameter("bgcolor").substring(1), 16));
  155.       ((Component)this).setBackground(this.backCol);
  156.       this.loadImage();
  157.    }
  158.  
  159.    public void update(Graphics g) {
  160.       this.paint(g);
  161.    }
  162.  
  163.    public void paint(Graphics g) {
  164.       if (this.frameNo < this.frames) {
  165.          g.drawImage(this.origImg, 0, this.frameNo * this.frameNo * this.field_1 / ((this.frames - 1) * (this.frames - 1)) - this.field_1, this);
  166.       } else if (this.frameNo == this.frames && this.animReady) {
  167.          g.drawImage(this.origImg, 0, 0, this);
  168.       } else if (this.frameNo > this.frames && this.animReady) {
  169.          int i = this.frameNo - this.frames;
  170.          g.drawImage(this.animImg, 0, -i * this.field_1, this);
  171.       } else if (this.origImg != null) {
  172.          g.drawImage(this.origImg, 0, 400, this);
  173.       }
  174.  
  175.    }
  176.  
  177.    public void createAnim() {
  178.       System.gc();
  179.       if (this.backImg == null) {
  180.          this.backImg = ((Component)this).createImage(this.field_0 * 3 >> 1, this.field_1 << 1);
  181.          this.backG = this.backImg.getGraphics();
  182.          this.animImg = ((Component)this).createImage(this.field_0, this.frames * this.field_1);
  183.          this.finG = this.animImg.getGraphics();
  184.          this.backG.setColor(this.backCol);
  185.       }
  186.  
  187.       for(int phase = 0; phase < this.frames; ++phase) {
  188.          this.backG.fillRect(0, 0, this.field_0, this.field_1 << 1);
  189.          this.backG.drawImage(this.origImg, 0, 0, this);
  190.          this.rotateImage(this.backG, 1.8849555921538759 * (double)phase * (double)phase / (double)this.frames / (double)this.frames);
  191.          this.finG.drawImage(this.backImg, 0, phase * this.field_1, this);
  192.       }
  193.  
  194.       this.animReady = true;
  195.    }
  196. }
  197.