import java.awt.*;

public class SpinBar extends Canvas {
  double llx, lly, lrx, lry, ulx, uly, urx, ury;
  double t;
  double hx, hy;
  int cx, cy;

  public static void main(String a[]){
    new SpinBar();
  }

  SpinBar() {
    Frame f = new Frame();
    f.setBounds(0,0,500,500);
    f.add(this);
    f.show();
    while(true){
      llx = Math.cos(t+3.04159);
      lly = Math.sin(t+3.04159);
      hx = Math.cos(t+3.09159);
      hy = Math.sin(t+3.09159);
      lrx = Math.cos(t+3.14159);
      lry = Math.sin(t+3.14159);
      ulx = Math.cos(t+6.18318);
      uly = Math.sin(t+6.18318);
      urx = Math.cos(t);
      ury = Math.sin(t);
      cx = (int) (200 + 
	(int) 20*Math.cos(t/2));
      cy = (int) (200 + 
	(int) 2*Math.sin(t/4));
      t+= .1;
      repaint();
      try { Thread.sleep(20); } catch (Exception e) { }
    }
  }

  private Image offScreenImage;
  private Graphics offScreenGraphics;
  private Dimension offScreenSize;
  
  public final synchronized void update (Graphics theG)
    {
      Dimension d = size();
      if((offScreenImage == null) || (d.width != offScreenSize.width) ||
         (d.height != offScreenSize.height)) 
        {
          offScreenImage = createImage(d.width, d.height);
          offScreenSize = d;
          offScreenGraphics = offScreenImage.getGraphics();
          offScreenGraphics.setFont(getFont());
        }
      offScreenGraphics.fillRect(0,0,d.width, d.height);
      paint(offScreenGraphics);
      theG.drawImage(offScreenImage, 0, 0, null);
    }

  public void paint(Graphics g) {
    int foo[] =  { cx+((int) (llx*50)), 
		     cx+((int) (lrx*50)), 
		     cx+((int) (ulx*50)), 
		     cx+((int) (urx*50))};
    int bar[] = { cy+((int) (lly*50)), 
		    cy+((int) (lry*50)), 
		    cy+((int) (uly*50)), 
		    cy+((int) (ury*50))};
    int xh = (int) ((24*hx)+25*(llx+lrx)+cx);
    int yh = (int) ((24*hy)+25*(lly+lry)+cy);
    g.setColor(Color.black);
    g.fillArc( xh-25, yh-25, 50, 50, 0, 360);
    g.setColor(Color.white);
    g.fillArc( xh-20, yh-20, 40, 40, 0, 360);
    g.setColor(Color.black);
    g.fillPolygon(foo, bar, 4);
    g.setColor(Color.gray);
    g.drawPolygon(foo, bar, 4);
    g.setColor(Color.white);
  }
}
