こちら。
int x, y, vx, vy;
void setup() {
smooth();
size(800, 800);
x=width/2;
y=height/2;
background(255);
int v=20;
vx=int(random(-1*v, v));
int a;
if (random(1)>0.5) {
a=1;
} else {
a=-1;
}
vy=a*int(sqrt(pow(v, 2)-pow(vx, 2)));
}
void draw() {
float a=random(1, 4);
int xnew=x+int(a*vx);
int ynew=y+int(a*vy);
if (xnew<0) {
xnew=0;
vx=-1*vx;
vy=int(vy*random(0.9, 1.1));
}
if (xnew>width) {
xnew=width;
vx=-1*vx;
vy=int(vy*random(0.9, 1.1));
}
if (ynew<0) {
ynew=0;
vy=-1*vy;
vx=int(vx*random(0.9, 1.1));
}
if (ynew>height) {
ynew=height;
vy=-1*vy;
vx=int(vx*random(0.8, 1.2));
}
if (vx*vx<30) {
vx=int(random(-20, 20));
}
if (vy*vy<30) {
vy=int(random(-20, 20));
}
stroke(random(255), random(255), random(255));
strokeWeight(random(30));
line(x, y, xnew, ynew);
x=xnew;
y=ynew;
if (frameCount%10==0) {
fill(255, 20);
noStroke();
rect(0, 0, width, height);
}
}