// Henon's strange attractor

import java.awt.*;

public class Henon extends java.applet.Applet implements Runnable {
  Thread attract=null;
  double x, y;

  public void init() {
    setBackground(Color.black);
    setForeground(Color.white);
    x=0.8; y=0; 
  }

  public void paint(Graphics g) {
    double xx, yy, zz;

    xx=1+y-1.4*x*x;
    yy=0.3*x;
     g.drawLine((int)(x*175+250),(int)(-y*400+250),(int)(x*175+250),(int)(-y*400+250));
    x=xx; y=yy;
  }

/*
 public void update(Graphics g) {
        g.setColor(getBackground());
        g.fillRect(0, 0, width, height);
        g.setColor(getForeground());
        paint(g);
    }
*/

  public void update(Graphics g) {
    paint(g);
  }

  public void start() {
    if (attract==null) {
      attract = new Thread(this);
      attract.start();
    }
  }

  public void stop() {
    if (attract!=null) {
      attract.stop();
      attract=null;
    }
  }

  public void run() {
    while (true) {
      try {
        Thread.currentThread().sleep(10);
      } catch (InterruptedException e) {
        break;
      }
      repaint();
    }
  }
}

