こちらを参考にしました。
Processing.jsでweb上で動かすとこんな感じやこんな感じ。
int r = 3;
int v = 5;
int x = 400;
int y = 400;
int c=0;
void setup() {
size(1000, 1000);
background(255);
noStroke();
fill(c);
x=width/2;
y=height/2;
}
void draw() {
fill(c);
float th=random(0,2*PI);
x += int(v*cos(th));
y += int(v*sin(th));
if(x>width) x=0;
if(x<0 if="" x="width;" y="">height) y=0;
if(y<0 c="" if="" y="height;">255) c=0;
}
0>0>
