01: import java.applet.*;
02: import java.awt.*;
03: import JSci.maths.chaos.*;
04:
05: /**
06: * Cat map transforms.
07: * @author Mark Hale
08: * @version 1.2
09: */
10: public final class CatTransform extends Applet implements Runnable {
11: private CatMap cm;
12: private double p1[], p2[], p3[], p4[];
13: private Thread thr;
14: private int xScale, yScale;
15: private int p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
16: private int iteration;
17:
18: public void init() {
19: cm = new CatMap();
20: p1 = new double[2];
21: p2 = new double[2];
22: p3 = new double[2];
23: p4 = new double[2];
24: p1[0] = 0.1;
25: p1[1] = 0.1;
26: p2[0] = 0.9;
27: p2[1] = 0.1;
28: p3[0] = 0.9;
29: p3[1] = 0.9;
30: p4[0] = 0.1;
31: p4[1] = 0.9;
32: xScale = getSize().width;
33: yScale = getSize().height;
34: iteration = 0;
35: }
36:
37: public void start() {
38: if (thr == null)
39: thr = new Thread(this );
40: thr.start();
41: }
42:
43: public void stop() {
44: thr = null;
45: }
46:
47: private int dataToScreenX(double x) {
48: return (int) Math.round(x * xScale);
49: }
50:
51: private int dataToScreenY(double y) {
52: return (int) Math.round(y * yScale);
53: }
54:
55: public void run() {
56: while (thr == Thread.currentThread()) {
57: p1x = dataToScreenX(p1[0]);
58: p1y = dataToScreenY(p1[1]);
59: p2x = dataToScreenX(p2[0]);
60: p2y = dataToScreenY(p2[1]);
61: p3x = dataToScreenX(p3[0]);
62: p3y = dataToScreenY(p3[1]);
63: p4x = dataToScreenX(p4[0]);
64: p4y = dataToScreenY(p4[1]);
65: repaint();
66: try {
67: Thread.sleep(200);
68: } catch (InterruptedException e) {
69: }
70: p1 = cm.map(p1);
71: p2 = cm.map(p2);
72: p3 = cm.map(p3);
73: p4 = cm.map(p4);
74: iteration++;
75: }
76: }
77:
78: public void paint(Graphics g) {
79: showStatus("Iteration = " + iteration);
80: g.drawLine(p1x, p1y, p2x, p2y);
81: g.drawLine(p2x, p2y, p3x, p3y);
82: g.drawLine(p3x, p3y, p4x, p4y);
83: g.drawLine(p4x, p4y, p1x, p1y);
84: }
85: }
|