Particle [] ps = new Particle[50];
for (int i=0;i<ps.length;i++) {
paddle = new Paddle(100,20);
for (int i=0;i<ps.length;i++) {
for (int j=i+1;j<ps.length;j++) {
for (int k=j+1;k<ps.length;k++) {
ps[i].displayTriangle(ps[j], ps[k]);
ps[i].displayConnection(ps[j]);
Paddle(float w,float h) {
loc = new PVector(width/2,height/2);
loc.x = lerp(loc.x, mouseX, 0.3);
loc.y = lerp(loc.y, mouseY, 0.3);
rect(loc.x, loc.y, w, h);
loc = new PVector(random(width), random(height));
vel = new PVector(random(0.5, 3), random(0.5, 2));
acc = new PVector(random(-0.1, 0.1), random(0.1, 0.4));
c = color(random(360), 255, 255);
private void collide(Paddle pd){
if (loc.x<0 || loc.x>width) vel.x = -vel.x;
if (loc.y>height) reset();
if (loc.y>=mouseY-pd.h/2 && loc.y<=mouseY+pd.h/2 && loc.x>=mouseX-pd.w/2 && loc.x<=mouseX+pd.w/2) {
void displayConnection(Particle p) {
float dst = dist(loc.x, loc.y, p.loc.x, p.loc.y);
float avgHue = (hue(c)+hue(p.c))*0.5;
float alpha = (thres-dst)/thres*255;
strokeWeight((thres-dst)*0.1);
stroke(avgHue, saturation, 255, alpha);
line(loc.x, loc.y, p.loc.x, p.loc.y);
void displayTriangle(Particle p1, Particle p2) {
float dst1 = dist(loc.x, loc.y, p1.loc.x, p1.loc.y);
float dst2 = dist(loc.x, loc.y, p2.loc.x, p2.loc.y);
float dst3 = dist(p1.loc.x, p1.loc.y, p2.loc.x, p2.loc.y);
float sp = (dst1+dst2+dst3)*0.5;
float area = sqrt(sp*(sp-dst1)*(sp-dst2)*(sp-dst3));
if (area < areaThres && dst1<thres && dst2<thres && dst3<thres) {
float avgHue = (hue(c)+hue(p1.c)+hue(p2.c))*0.33;
fill(avgHue, saturation, 255, (1-area/areaThres)*255);
triangle(loc.x, loc.y, p1.loc.x, p1.loc.y, p2.loc.x, p2.loc.y);
loc.set(random(width), 0);