int nParticles = 50; Particle parray[]; float DRAG = 0.95; int[] generation; color[] goodcolor = { #CD540A, #AE7450, #AD611E, #E97913, #4D3711, #E4CC62, #AFAC37, #B1AF4F, #929553, #D1DE8C, #D0E5AA, #5A8D67, #5A8D67, #334B4E, #3D737D, #8798C9, #6D7590, #8B95BA, #A9A8B9, #F7F5F6, }; void setup(){ size(400,400, P3D); generation = new int[nParticles]; for (int i=0; i -60){ fx = -fx; fy = -fy; } */ if (dh <= (parray[i].radius + parray[j].radius)){ fx = -2*fx; fy = -2*fy; if(dh <=(parray[i].radius + parray[j].radius)/2){ parray[i].radius += 0.025; parray[j].radius += 0.025; } } parray[i].accumulateForce(-fx, -fy); parray[j].accumulateForce( fx, fy); float rx = rstrength * random(-1,1); float ry = rstrength * random(-1,1); parray[i].accumulateForce(rx, ry); } } } for (int i=0; i 80){ generation[i]++; if (generation[i]>20) { generation[i] = 0; } parray[i].radius = 3; parray[i].thiscolor = goodcolor[generation[i]]; } } } //======================================= class Particle { float px, py; float vx, vy; float fx, fy; float mass; float radius; color thiscolor; Particle(float xin, float yin, color somecolor){ px = xin; py = yin; vx = 0; vy = 0; fx = 0; fy = 0; mass = 10; radius = 5; thiscolor = somecolor; } void clearForces(){ fx = 0; fy = 0; } void accumulateForce(float gx, float gy){ fx += gx; fy += gy; } void update(){ vx += fx / mass; vy += fy / mass; vx *= DRAG; vy *= DRAG; px += vx; py += vy; } void screenWrap(){ if (py<-100){ py += height; } else if (py>height){ py -= height; } if (px<-100){ px += width; } else if (px>width+100){ px -= width; } else if (py>height+100){ py -= height; } } void render(){ stroke(0, 255-radius*3); fill(thiscolor, 255-radius*3); ellipse(px,py,radius,radius); } }