Files
sunny9898/task8/wk8/wk8_example6/wk8_example6.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

67 lines
1.1 KiB
Plaintext

int num = 50;
Walker[] walkers = new Walker[num];
void setup() {
//fullScreen();
size(600, 600);
background(255);
noStroke();
textSize(30);
for (int i = 0; i < num; i++)
walkers[i] = new Walker(i);
}
void draw() {
fill(255, 50); // fading
rect(0, 0, width, height);
for (int i = 0; i < num; i++)
walkers[i].update();
}
class Walker {
// fields
String s;
float x, y, a;
float tx, ty, ta;
color c;
// constructor
Walker(int i) {
s = nf(i);
x = random(width);
y = random(height);
tx = random(1000);
ty = random(1000);
ta = random(1000);
c = color(random(255),random(255),random(255));
}
// method
void update() {
pushMatrix();
translate(x, y);
rotate(a);
fill(c, 50);
text(s, 0, 0);
popMatrix();
tx += 0.01;
ty += 0.01;
ta += 0.001;
x += noise(tx)*4-2;
y += noise(ty)*4-2;
a += noise(ta)*0.1-0.05;
if (x<0)
x += width;
else if (x>width)
x -= width;
if (y<0)
y += height;
else if (y>height)
y -= height;
}
}