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);} }