Ciao 访客, welcome back to old school! :p
//Raven Kwok | 郭锐文//Email: raystain@gmail.com//Blog: the-moor.blogbus.com//Vimeo: vimeo.com/ravenkwok//Weibo: weibo.com/ravenkwok import megamu.mesh.*; int total;float xOffset, yOffset;float [][] pos;Particle [] particles;Delaunay delaunay; void setup() { size(500, 500); smooth(); background(255); total = 300; xOffset = width/2; yOffset = height/2; particles = new Particle[total]; for (int i=0;i<total;i++) { particles[i] = new Particle(xOffset, yOffset); }}void draw() { background(255); for (int i=0;i<total;i++) { particles[i].update(); particles[i].display(); } pos = new float[total][2]; for ( int j=0; j<pos.length;j++) { pos[j][0] = particles[j].xCurr; pos[j][1] = particles[j].yCurr; } delaunay = new Delaunay(pos); float[][] edges = delaunay.getEdges(); for (int i=0; i<edges.length; i++) { float startX = edges[i][0]; float startY = edges[i][1]; float endX = edges[i][2]; float endY = edges[i][3]; float trans = 255-dist(startX, startY, endX, endY)*4; float sw = 5/(dist(startX, startY, endX, endY)+1); strokeWeight(sw); stroke(0, trans); line(startX, startY, endX, endY); }}void keyPressed() { if (key =='r') { for (int i=0;i<total;i++) { particles[i].reset(); } }}class Particle { float xCurr, yCurr; float xInit, yInit; float xo,yo; Particle(float xo_, float yo_) { xo = xo_; yo = yo_; float degreeTemp = random(360); float rTemp = random(10, 200); xInit = cos(radians(degreeTemp))*rTemp+xo; yInit = sin(radians(degreeTemp))*rTemp+yo; xCurr = xInit; yCurr = yInit; } void update() { float x0 = xCurr; float y0 = yCurr; float a = mouseX-x0; float b = mouseY-y0; float r = sqrt(a*a+b*b); float quer_fugir_x = xCurr-(a/r)*100/r; float quer_fugir_y = yCurr-(b/r)*100/r; float quer_voltar_x = (xInit-x0)/10; float quer_voltar_y = (yInit-y0)/10; xCurr = quer_fugir_x+quer_voltar_x; yCurr = quer_fugir_y+quer_voltar_y; } void display() { strokeWeight(1); stroke(0); point(xCurr, yCurr); } void reset() { float degreeTemp = random(360); float rTemp = random(10, 200); xInit = cos(radians(degreeTemp))*rTemp+xo; yInit = sin(radians(degreeTemp))*rTemp+yo; }}
//Raven Kwok (aka Guo Ruiwen)//oct22a_2011/* raystain@gmail.comtwitter.com/ravenkwokflickr.com/ravenkwokweibo.com/ravenkwokthe-moor.blogbus.com note: Update on Sep.03, 2012. _1. Some modification on the motion of each particle, thanks to Ale( http://www.openprocessing.org/portal/?userID=12899 )'s advice :)_2. Each particle now has it own "tensile force". This "force" is indicated by size of the block.*/import megamu.mesh.*;int count;float xOffset, yOffset;float [][] pos;Particle [] particles;Delaunay delaunay;void setup() { size(600, 600, P2D); smooth(); rectMode(CENTER); count = 1000; xOffset = width/2; yOffset = height/2; particles = new Particle[count]; for (int i=0;i<count;i++) { particles[i] = new Particle(xOffset, yOffset); }}void draw() { background(255); for (int i=0;i<count;i++) { particles[i].update(); } pos = new float[count][2]; for ( int j=0; j<pos.length;j++) { pos[j][0] = particles[j].xCurr; pos[j][1] = particles[j].yCurr; } delaunay = new Delaunay(pos); float[][] edges = delaunay.getEdges(); for (int i=0; i<edges.length; i++) { float startX = edges[i][0]; float startY = edges[i][1]; float endX = edges[i][2]; float endY = edges[i][3]; float distance = dist(startX, startY, endX, endY); float trans = 255-map(distance,0,60,0,255); float sw = 2/sqrt(distance+1); strokeWeight(sw); stroke(0, trans); line(startX, startY, endX, endY); } for (int i=0;i<count;i++) { particles[i].display(); }}void keyPressed() { if (key =='r') { for (int i=0;i<count;i++) { particles[i].reset(); } }}class Particle { float xCurr, yCurr; float xInit, yInit; float xo,yo; float pushForce; float recoverForce; Particle(float xo, float yo) { this.xo = xo; this.yo = yo; float degreeTemp = random(360); float rTemp = random(10, 180); xInit = cos(radians(degreeTemp))*rTemp+xo; yInit = sin(radians(degreeTemp))*rTemp+yo; xCurr = xInit; yCurr = yInit; pushForce = random(10,300); recoverForce = random(10,100); } void update() { float x0 = xCurr; float y0 = yCurr; float a = mouseX-x0; float b = mouseY-y0; float r = pushForce/(a*a+b*b); float quer_fugir_x = xCurr-a*r; float quer_fugir_y = yCurr-b*r; float quer_voltar_x = (xInit-x0)/recoverForce; float quer_voltar_y = (yInit-y0)/recoverForce; xCurr = quer_fugir_x+quer_voltar_x; yCurr = quer_fugir_y+quer_voltar_y; } void display() { pushMatrix(); translate(xCurr,yCurr); rotate(radians(360*noise(xCurr*0.01,yCurr*0.01))); float diam = (pushForce/recoverForce)/dist(xCurr,yCurr,mouseX,mouseY)*100; strokeWeight(1); stroke(0,100); fill(255); rect(0, 0,diam,diam); popMatrix(); } void reset() { float degreeTemp = random(360); float rTemp = random(10, 180); pushForce = random(10,300); recoverForce = random(10,100); xInit = cos(radians(degreeTemp))*rTemp+xo; yInit = sin(radians(degreeTemp))*rTemp+yo; }}