/*
* attact.java
*
* Lorenz's strange attractor, found at
* http://www.sat.t.u-tokyo.ac.jp/~hideyuki/java/attract.html
*
*/
import java.awt.*;
public class Attract extends java.applet.Applet implements Runnable {
Thread attract=null;
double x, y, z;
public void init() {
setBackground(Color.black);
setForeground(Color.white);
x=0; y=20; z=20;
}
public void paint(Graphics g) {
double xx, yy, zz;
xx=x+0.01*(-10*x+10*y);
yy=y+0.01*(28*x-y-x*z);
zz=z+0.01*(-8*z/3+x*y);
g.drawLine((int)(x*10+250),(int)(-z*10+500),(int)(xx*10+250),(int)(-zz*10+500));
x=xx; y=yy; z=zz;
}
/* 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();
}
}
}