I am writing some code in processing to display a random walker using the Monte Carlo algorithm.
Now I have specified a walker class with inside two important methods a step function which controls the movement and a stepsize function which controls the speed and direction.
But for some reason I cannot properly call the stepsize method in the step method. As a result,the program draws nothing on the screen. The code executes, I have no errors.
My code:
import java.util.*;
class Walker {
float y;
float x;
float monte_carlo;
Walker() {
x = width/2;
y= height/2;
}
void display(){
stroke(0);
point(x,y);
}
float stepsize (float r1) {
while (true) {
r1 = random(0,10);
float probability = r1;
float r2 = random(0,10);
if (r2 < probability) {
return r1;
}
}
}
void step() {
x += stepsize(monte_carlo);
y += stepsize(monte_carlo);
}
}
Walker w;
void setup() {
size(400,400);
w = new Walker();
background(255);
}
void draw() {
w.display();
w.step();
}
This problem has been bothering me for a while and I would really appreciate it if someone could enlighten me!