Kurze Beschreibung des Programmes RandomWalk

 

Dieser Java-Code beschreibt graphisch die Bewegung eines Punktes, welcher sich zufällig in eine der 4 Richtungen bewegt, wobei die Wahrscheinlichkeit für jede Richtung dieselbe ist.
Um die ausführbare Datei RandomWalk.jar herunterzuladen, drücke bitte auf folgenden Link RandomWalk

				
					public class RandomWalk extends JFrame {

	private static final long serialVersionUID = 1L;
	int x, y;

	RandomWalk() {
		setSize(900, 900);
		setVisible(true);
	}

	void walk() {
		double zufall;
		zufall = Math.random();
		if (zufall < 0.25) {
			y = y + 1;
		}
		if ((zufall > 0.25) && (zufall < 0.5)) {
			y = y - 1;
		}
		if ((zufall > 0.5) && (zufall < 0.75)) {
			x = x + 1;
		}
		if ((zufall > 0.75)) {
			x = x - 1;
		}
	}

	public void paint(Graphics g) {
		for (int i = 0; i < 300000; i++) {
			{
				g.setColor(new Color(i * 50));
				walk();
				g.drawOval(450 + x, 450 + y, 1, 1);

			}
		}
	}

	public static void main(String[] args) {
		RandomWalk rw = new RandomWalk();

	}

}