ArrayList
centers = new ArrayList();
void setup(){
size(500,500);
for(int i = 0; i < 12; i++){
centers.add(new Center());
}
}
int PTS = 50;
void moveAway(){
for(Center c : centers){
c.a = atan2(c.y - mouseY, c.x - mouseX);
}
}
void draw(){
background(200);
if(mousePressed)moveAway();
for(Center c : centers){
c.move();
}
float sz = width/PTS;
for(int i = 0; i < PTS; i++){
for(int j = 0; j < PTS; j++){
float min = 99999;
float x = i * sz;
float y = j * sz;
for(Center c : centers){
float d = dist(x,y,c.x,c.y);
if(d < min) {
min = d;
}
}
noStroke();
float brite = 255 - (min*.8);
fill(brite,brite,255);
rect(x,y,sz,sz);
}
}
strokeWeight(2);
//stroke(255);
for(Center c1 : centers){
for(Center c2 : centers){
if(c1 != c2 && dist(c1.x,c1.y,c2.x,c2.y) < 2*width/PTS){
c1.a = random(PI*2);
c2.a = random(PI*2);
}
}
}
//fill(0);
//text(frameRate,100,100);
}
class Center{
float x,y,xs,ys, a;
Center(){
x = random(width);
y = random(height);
a = random(2 * PI);
}
void move(){
if(y > height) {
a = random(PI) + PI;
y = height;
}
if(x > width){
a = random(PI) + (PI /2);
x = width;
}
if(y < 0) {
a = random(PI) ;
y = 0;
}
if(x < 0) {
a = random(PI) + (PI * 3 /2);
x = 0;
}
xs = (150/frameRate)*cos(a);
ys = (150/frameRate)*sin(a);
x += xs;
y += ys;
}
void draw(){
line(250,250,x,y);
}
}