Walker w;

void setup(){
 size(800,600);

 w = new Walker();
 background(255);
}

void draw(){
 w.step();
 w.render();
}


class Walker {
 int x, y;

Walker() {
   x = width/2;
   y = height/2;
 }

 void render() {
   stroke(0);
   point(x, y);
 }

void step() {

   /*
    int choice = int(random(4));
    if (choice == 0){
    x++;
    }else if (choice == 1){
    x–;
    }else if (choice == 2){
    y++;
    }else {
    y–;
    }

    */

   float r = random(1);
   //40% of moving to the right!
   if (r < 0.4) {
     x++;
   } else if (r<0.6) {
     x–;
   } else if (r<0.8) {
     y++;
   }

   x = constrain(x, 0, width-1);
   y = constrain(y, 0, height-1);
 }
}
Back to Top