import java.awt.*; import java.applet.*; public class BrownMo7 extends Applet implements Runnable { Thread runner; int z,w; int x = 250; int y = 200; public void init() { Label theTitle = new Label("Brownian Motion Movie"); Label myName = new Label(" Paul Garrett garrett@math.umn.edu"); add(theTitle); add(myName); } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner.stop(); runner = null; } } void pause(int time) { try { Thread.sleep(time); } catch ( InterruptedException e) { } } public void update(Graphics g) { // don't clear the screen paint(g); } public void run() { setBackground(Color.darkGray); setForeground(Color.red); for (int i=0 ; i < 2000 ; i++ ) { twoConsecutivePoints(i); repaint(); pause(150); } } public void paint(Graphics g) { g.drawLine(x,y,z,w); } public void twoConsecutivePoints(int j) { int angle = (int) Math.floor(Math.random()*360); z = x; w = y; x = z + (int) (14 * Math.cos(angle)); y = w + (int) (14 * Math.sin(angle)); } }