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

40 lines
587 B
Plaintext

// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// A random walker object!
class Walker {
float x, y;
float tx, ty;
float prevX, prevY;
Walker() {
tx = 0;
ty = 10000;
x = map(noise(tx), 0, 1, 0, width);
y = map(noise(ty), 0, 1, 0, height);
}
void render() {
stroke(255);
line(prevX, prevY, x, y);
}
// Randomly move according to floating point values
void step() {
prevX = x;
prevY = y;
x = map(noise(tx), 0, 1, 0, width);
y = map(noise(ty), 0, 1, 0, height);
tx += 0.01;
ty += 0.01;
}
}