int MAX = 100; ArrayList nlist = new ArrayList(); int choice=1; PFont font; void setup() { size(800,600); background(0); smooth(); for (int i = 0; i < MAX; i++) { nlist.add(new Node( random(100,width-100),random(100,height-100),10, .01)); } //Create Font font = loadFont("ArialMT-24.vlw"); textFont(font, 12); } void draw() { //background(0); fill(0,0,0,10); rect(0,0,width, height); setsink(choice); collide(); renderfield(); renderMODE(); } //PAGE 2 void keyPressed() { if(key=='1') { choice=1; } if(key=='2') { choice=2; } if(key=='3') { choice=3; } if(key=='4') { choice=4; } if(key=='5') { choice=5; } if(key=='6') { choice=6; } } void renderMODE() { fill(30); text("change mode by hitting keys 1-6. you must click in window first", 10, height-20); text("current choice: "+choice, 10, height-7); } void renderfield() { for (int i = 0; i < nlist.size(); i++) { Node b = (Node) nlist.get(i); b.render(); } } void setsink(int c) { for (int i = 0; i < nlist.size(); i++) { Node b = (Node) nlist.get(i); //GOOD if(c==1) { b.setSINK(.05);//.1 really good } //GOOD if(c==2) { b.setSINK(.02+.1*sin(radians((millis()+i*25)/20))); //.1+.1 /20 REALLY GOOD } //GOOD TOP AND THEN BOTH if(c==3) { b.setSINK(.02+.1*sin(radians((millis()+i*25)/(11+10*sin(radians(second())))))); //.1+.1 /20 REALLY GOOD b.setSINK(3*((i%2)*-2+1)*b.getSINK()); //Fascinating waving motion (use in tandem with above) } if(c==4) { b.setSINK(.02+.1*sin(radians((millis()+i*25)/(11+10*sin(radians(second())))))); //.1+.1 /20 REALLY GOOD } //GOOD if(c==5) { b.setSINK(.02+.1*sin(radians((millis()+i*25)/(20+i)))); //.1+.1 /20 this sets the periods differently } //GOOD bellow if(c==6) { b.setSINK(.02+.1*sin(radians((millis()+i*25)/(20+20*(i%2))))); //.1+.1 /20 this sets the periods differently\ } } } void collide() { for(int i=0; i< nlist.size(); i++) { for(int j=0; j< nlist.size(); j++)//must go from 0 not i { if(j != i) { Node n1 = (Node) nlist.get(i); Node n2 = (Node) nlist.get(j); attract(n1, n2, -1); } } } } void attract(Node n1, Node n2, float cpolarity) { float mx, my, distm, nx1, ny1; float added_d; added_d = (n1.getD()+n2.getD())/2; mx = n1.getX()-n2.getX(); my = n1.getY()-n2.getY(); distm = sqrt(mx*mx+my*my); //There can be constant with dist or /dist //nx1=n1.getX()-mx*(distm-10)/distm *.1*n2.getSINK(); //ny1=n1.getY()-my*(distm-10)/distm *.1*n2.getSINK(); nx1=n1.getX()-mx/distm *n2.getSINK()/3;//(distm); ny1=n1.getY()-my/distm *n2.getSINK()/3;//(distm);//or divide by 1 if (dist(nx1,ny1,n2.getX(),n2.getY()) > added_d) { n1.setX(nx1); n1.setY(ny1); } else { nx1=n1.getX()- mx/distm *cpolarity*added_d; ny1=n1.getY()- my/distm *cpolarity*added_d; n1.setX(nx1); n1.setY(ny1); } //I'd rather see an ellipse // if( (sq(width/2-nx1)+sq(height/2-ny1))>300 ) // { // } if( nx1 < 0) {nx1=0;n1.setX(nx1);} if( nx1 > width) {nx1=width;n1.setX(nx1);} if( ny1 < 0) {ny1=0; n1.setY(ny1);} if( ny1 > height) {ny1=height; n1.setY(ny1);} } //Page 3 class Node { float x; float y; float d; float sink; Node(float x_, float y_, float d_, float sink_) { x=x_; y=y_; d=d_; sink=sink_; }//END sink float getX() {return x;} void setX(float x_) {x = x_;} float getY() {return y;} void setY(float y_) {y = y_;} float getD() {return d;} void setD(float d_) {d = d_;} float getSINK() {return sink;} void setSINK(float sink_) {sink = sink_;} void render() { noStroke(); fill(255); ellipse(x,y,d,d); } }