xxxxxxxxxx
ArrayList<Particle> particles;
int max=80,min=10;
void setup(){
size(800,600);
particles = new ArrayList<Particle>();
for(int i = 0; i < 100; i++){
particles.add(new Particle());
}
}
void draw(){
noStroke();
fill(0,10,20,75);
rect(0,0,width,height);
for(Particle p: particles){
fill(#5ABEF0,p.trans*4);
ellipse(p.pos.x, p.pos.y, p.rad, p.rad);
p.update();
}
for(int i = 0; i < particles.size() - 2; i++){
Particle p1 = particles.get(i);
for(int j = i + 1; j < particles.size() - 1; j++){
Particle p2 = particles.get(j);
if(PVector.dist(p1.pos, p2.pos) <= 100 ){
float t=(p1.trans+p2.trans)/1.5;
stroke(90,210,230,t);
strokeWeight(1);
line(p1.pos.x, p1.pos.y, p2.pos.x, p2.pos.y);
}
for(int k = j + 1; k < particles.size(); k++){
Particle p3 = particles.get(k);
if(PVector.dist(p1.pos, p2.pos) <= 80 && PVector.dist(p2.pos, p3.pos) <= 80 && PVector.dist(p3.pos, p1.pos) <= 80){
float t=(p1.trans+p2.trans+p3.trans)/4;
noStroke();
fill(90,210,230,t);
triangle(p1.pos.x, p1.pos.y, p2.pos.x, p2.pos.y, p3.pos.x, p3.pos.y);
}
}
}
}
}
class Particle {
PVector pos;
PVector vel;
float trans;
float rad=5;
float mult=1.25;
Particle(){
pos = new PVector(random(rad,width-rad), random(rad,height-rad));
float velAng = random(TWO_PI);
vel = new PVector(mult * cos(velAng), mult * sin(velAng));
trans=random(min,max);
}
void update(){
pos.add(vel);
if(pos.x < rad || pos.x >= width-rad){
vel.x *= -1;
}
if(pos.y < rad || pos.y >= height-rad){
vel.y *= -1;
}
}
}