Files
sunny9898/task8/_ref/noc-examples-processing-master/introduction/RandomWalkTraditional2/Walker.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

30 lines
491 B
Plaintext

// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// A random walker object!
class Walker {
int x,y;
Walker() {
x = width/2;
y = height/2;
}
void render() {
stroke(255);
point(x,y);
}
// Randomly move to any neighboring pixel (or stay in the same spot)
void step() {
int stepx = int(random(3))-1;
int stepy = int(random(3))-1;
x += stepx;
y += stepy;
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}