mirror of
https://github.com/processing/processing4.git
synced 2026-02-07 07:39:18 +01:00
31 lines
482 B
Plaintext
31 lines
482 B
Plaintext
// Daniel Shiffman
|
|
// The Nature of Code
|
|
// http://www.shiffman.net/
|
|
|
|
// A random walker object!
|
|
|
|
class Walker {
|
|
float x, y;
|
|
|
|
Walker() {
|
|
x = width/2;
|
|
y = height/2;
|
|
}
|
|
|
|
void render() {
|
|
stroke(255);
|
|
point(x, y);
|
|
}
|
|
|
|
// Randomly move according to floating point values
|
|
void step() {
|
|
float stepx = random(-1, 1);
|
|
float stepy = random(-1, 1);
|
|
x += stepx;
|
|
y += stepy;
|
|
x = constrain(x, 0, width-1);
|
|
y = constrain(y, 0, height-1);
|
|
}
|
|
}
|
|
|