PSystem ps; Particle p[][]; Spring s[][]; int BRANCHING[] = new int[10]; //desired numer of branches for each particle in next step int CURRENT_ROW[] = new int[10]; //number of members in current row int POPULATION_TOTAL[] = new int[10]; //total number of members after each row HScrollbar myscrollbar1, myscrollbar2,myscrollbar3,myscrollbar4,myscrollbar5,myscrollbar6; void setup() { create (0,0); branching(2,2,2,2,1,0); myscrollbar1 = new HScrollbar(50, height - 40, 270, 10, 3*5+1); myscrollbar2 = new HScrollbar(50, height - 60, 270, 10, 3*5+1); myscrollbar3 = new HScrollbar(50, height - 80, 270, 10, 3*5+1); myscrollbar4 = new HScrollbar(50, height - 100, 270, 10, 3*5+1); myscrollbar5 = new HScrollbar(50, height - 120, 270, 10, 3*5+1); myscrollbar6 = new HScrollbar(50, height - 140, 270, 10, 3*5+1); } void branching(int slider1, int slider2, int slider3, int slider4, int slider5, int slider6 ) { BRANCHING[0] = 1; BRANCHING[1] = slider1; BRANCHING[2] = slider2; BRANCHING[3] = slider3; BRANCHING[4] = slider4; BRANCHING[5] = slider5; BRANCHING[6] = slider6; BRANCHING[7] = 0; BRANCHING[8] = 0; } void create (int change, int horiz) { size(800,600); ps = (PSystem)loadPlugin("PSystem"); ps.defaultSpringRestLength = 1; ps.defaultSpringStrength = 0.15; CURRENT_ROW[0] = 1; //number of members in each (CURRENT) row POPULATION_TOTAL[0] = 1; //total number of members int ROWS = 0; for (int n = 0; n < BRANCHING.length ; n++) { //checks for end of the array if (BRANCHING[n] == 0) { break; } ROWS++; } Particle p[][] = new Particle[10][200]; Spring s[][] = new Spring[10][200]; for (int n = 0; n < ROWS ; n++) { if (n > 0) { CURRENT_ROW[n] = CURRENT_ROW[n-1] * BRANCHING[n]; POPULATION_TOTAL[n] = POPULATION_TOTAL[n-1] + CURRENT_ROW[n]; } for (int i = 1; i <= CURRENT_ROW[n]; i++) { //THE BOTTOM PARTICLE if (n==0 && i==1) { p[n][i] = new Particle (width/2, mouseY, 0); } else if (n==ROWS-1) { p[n][i] = new Particle ( i*30, 100, 0 ); } else { p[n][i] = new Particle ( width/2+i, 700 - (50 * n * n) , 0 ); } ps.addParticle (p[n][i]); if (n==0) { p[n][i].fix(); } if (n==ROWS-1) { if (change == 0) { p[n][i].fix(1,50); } if (change == 1 && ROWS - 1 < 5){ p[n][i].fix(1,50-((sqrt (i))*i-12*i)); } if (change == 2 && ROWS - 1 < 5){ p[n][i].fix(1,+(i)/4 + 100 +((sqrt (5*i))*i-6*i)); } if (change == 3 && ROWS - 1 < 5) { p[n][i].fix(1,+(i*i)/4 + 100+((sqrt (i))*i-12*i)); } if (change == 4 && ROWS - 1 < 5) { p[n][i].fix(1,100 + 10*sin(5*i)); } if (change == 5 && ROWS - 1 < 5) { p[n][i].fix(1,100 + 4*i + 10*sin(5*i)); } } ps.defaultSpringDamping = .025; if (n > 0) { //MAIN SPRINGS for (int k = 1; k <= CURRENT_ROW[n]; k++) { if (i<=BRANCHING[n]*k && i>BRANCHING[n]*(k-1) ) { s[n][i] = new Spring (p[n][i], p[n-1][k]); ps.addForce(s[n][i]); } } } if (i>1 && n==ROWS-1) { //HORIZONTAL SPRINGS FOR LAST ROW ps.defaultSpringRestLength = 50; ps.defaultSpringStrength = 1.5; ps.addSpring(p[n][i],p[n][i-1]); if (i>2) { //HORIZONTAL [n-2] SPRINGS FOR LAST ROW ps.addSpring(p[n][i],p[n][i-2]); } } if(horiz == 1) { if (i>1 && n 1) { spos = spos + (newspos-spos)/loose; } } int constrain(int val, int minv, int maxv) { return min(max(val, minv), maxv); } boolean over() { if(mouseX > xpos && mouseX < xpos+swidth && mouseY > ypos && mouseY < ypos+sheight) { return true; } else { return false; } } void draw() { fill(200); rect(xpos, ypos, swidth, sheight); if(over || locked) { fill(125, 125, 125); // color while active } else { fill(255, 255, 255); // color while inactive } rect(spos, ypos, sheight, sheight); } int getPos() { // convert spos to be values between // 0 and the total width of the scrollbar return spos * ratio; } }