/** * Program: Mix2 * @author: Paul Garrett, garrett@math.umn.edu * @version: Tue Dec 28 16:58:27 CST 1999 * * Purpose: * */ import java.awt.*; public class Mix2 extends java.applet.Applet implements Runnable { int a = 3; int b = 1; int c = 1; int d = 2; int aa = 1; int bb = 0; int cc = 0; int dd = 1; Thread th; int counter = 0; public void start() { if (th == null) { th = new Thread(this); th.start(); } } public void stop() { if (th != null) { th.stop(); th = null; } } public void pause(int time) { try { th.sleep( time ); } catch (Exception e) { // do nothing } // System.out.println("Waking up"); } public void run() { while (true) { pause( 1000 ); counter++; int atmp = aa; int btmp = bb; int ctmp = cc; int dtmp = dd; aa = a*atmp + b*ctmp; bb = a*btmp + b*dtmp; cc = c*atmp + d*ctmp; dd = c*btmp + d*dtmp; repaint(); // System.out.println("iterating"); } } public void paint(Graphics g) { int[] xy = new int[2]; int[] zw = new int[2]; g.setColor(Color.red); for (int i=0; i<100; i++) { // upper left 1/5 x 1/5 for (int j=0; j<100; j++) { xy[0] = i; xy[1] = j; zw = f(xy); g.fillRect(zw[0],zw[1],1,1); } } g.setColor(Color.blue); for (int i=100; i<200; i++) { for (int j=0; j<100; j++) { xy[0] = i; xy[1] = j; zw = f(xy); g.fillRect(zw[0],zw[1],1,1); } } g.setColor(Color.green); for (int i=0; i<100; i++) { for (int j=100; j<200; j++) { xy[0] = i; xy[1] = j; zw = f(xy); g.fillRect(zw[0],zw[1],1,1); } } g.setColor(Color.yellow); for (int i=100; i<200; i++) { for (int j=100; j<200; j++) { xy[0] = i; xy[1] = j; zw = f(xy); g.fillRect(zw[0],zw[1],1,1); } } // g.setColor(Color.black); // g.drawRect(0,0,500,500); } int[] f( int[] xy ) { // 499 is prime... int[] out = new int[2]; out[0] = (aa*xy[0]+bb*xy[1]) % 499; out[1] = (cc*xy[0]+dd*xy[1]) % 499; return out; } } /************************************************** * * The End * ***************************************************/