class Cube extends Particle { color ccolor; int sizeX = 20; int sizeY = 20; int sizeZ = 20; Cube(float x,float y, float z) { } public Cube(String type) { if ( type == "target") { ccolor = #FFF000; sizeX = 100; sizeY = 100; sizeZ = 100; } else if (type == "mouseCube") { ccolor = #77D8FF; sizeX = 10; sizeY = 10; sizeZ = 200; } else if (type == "mCube") { ccolor = #00FF00; sizeX = 10; sizeY = 10; sizeZ = 75; } else { ccolor = color(random(255),random(255),random(255)); sizeX = 15; sizeY = 15; sizeZ = 15; } } void draw() { push(); translate(pos[0], pos[1], pos[2]); /* if (this == mPart) { fill(#FFF000); box(100, 100, 100); }//white else if (this == a) { fill(#0FFFF0); box(20, 20, 100); }//light green-blue else if (this == n) { ccolor= color(random(255),random(255),random(255)); fill(ccolor); box(20,20,20); } else if (this == m) { ccolor= color(random(255),random(255),random(255)); fill(ccolor); box(20,20,20); } */ fill(ccolor); box(sizeX, sizeY, sizeZ); pop(); } } PSystem ps; Cube a; Cube b; Cube mPart; Cube n[] = new Cube[100]; Cube m[] = new Cube[100]; Cube f[] = new Cube[100]; Cube r; Cube s; Cube t; Cube u; //Arcball arcball; void setup() { size(800,800); ps = (PSystem)loadPlugin("PSystem"); //arcball = (Arcball)loadPlugin("Arcball"); a = new Cube("mouseCube"); a.setPos(width/2, height/2 - 50, 0); // I took out the axis fix to fix the distance between ouse and other //boxes a.fix(2,0); ps.addParticle(a); b =new Cube("mouseCube"); b.setPos(width,height,0); ps.addParticle(b); //b.fix(2,0); r =new Cube("mCube"); r.setPos(400,375,0); ps.addParticle(r); r.fix(); /* s =new Cube("mCube"); s.setPos(775,25,0); ps.addParticle(s); s.fix(); t =new Cube("mCube"); t.setPos(25,775,0); ps.addParticle(t); t.fix(); u =new Cube("mCube"); u.setPos(775,775,0); ps.addParticle(u); u.fix(); */ mPart = new Cube("target"); mPart.setPos(0, height/2, 20); //mPart.fix(0,400); //mPart.fix(1,400); //mPart.fix(2,0); ps.addParticle(mPart); ps.addMagnet(mPart, 50000); a.enableCollision(100); mPart.enableCollision(50); b.enableCollision(100); // I turned this into an array for f - before the mouseCUbe ended at the //end of the string since you pass it through as you create the cubes - now //it stays at the top for (int i=0;i<20;i++) { f[i]=new Cube(" "); f[i].ccolor = color(200,0,0); f[i].setPos(mouseX+i*20,mouseY,0); ps.addParticle(f[i]); if (i==0) { ps.addSpring(a,f[i],2,1,1); } else ps.addSpring(f[i-1],f[i],2,1,1); f[i].enableCollision(100); //f[i].mass=5; //a=f; } ps.addSpring(r,mPart,.01,.01,10); ps.addSpring(r,b,.01,.01,10); /*ps.addSpring(s,mPart,.001,.001,1); ps.addSpring(t,mPart,.001,.001,1); ps.addSpring(u,mPart,.001,.001,1); */ ps.setGravity(0, .3, 0); ps.drag = .01; makeSpringBall(b,50,20); } float time=0; void mouseDragged() { a.setPos(mouseX, mouseY, 0); } void mousePressed() { a.setPos(mouseX, mouseY, 0); } void firetleft() { int j=1; j=j+1; if (j==6) { n[j].die(); } n[j]= new Cube(" "); n[j].pos[0]=0; n[j].pos[1]=50; n[j].pos[2]=0; ps.addParticle(n[j]); n[j].velocity[0]=random(45); n[j].velocity[1]=random(40); n[j].enableCollision(20); n[j].fix(2,0); } void firetlefta() { int k=1; k=k+1; if (k==6) { m[k].die(); } m[k]= new Cube(" "); m[k].pos[0]=800; m[k].pos[1]=50; m[k].pos[2]=0; ps.addParticle(m[k]); m[k].velocity[0]=random(-40); m[k].velocity[1]=random(-35); m[k].enableCollision(20); m[k].fix(2,0); } int skipLoops=15; void loop() { if (frame % skipLoops == 0) { firetleft(); firetlefta(); } //translate(width/2,height/4); //arcball.run(); //b.setPos(100*sin(time/27),100*sin(time/20),200*sin(time/57)); //b.setPos(800,800,0); background(#00AAAA); a.setPos(mouseX, mouseY, 0); stroke(0, 100, 0, 100); fill(255, 0, 0); ps.draw(); time=time+1; } void makeSpringBall(Particle startParticle, float size, int res) { float top[] = new float[3]; float stackIncrement = TWO_PI/res; float rotIncrement= TWO_PI/res; float y, angle, stackSize; float topAngle = 0; y = startParticle.pos[1]; int nSlices; int nStacks = res / 2; Particle allInBall[][] = new Particle[nStacks][res]; for (int stack = 0; stack < nStacks ; stack++) { topAngle += stackIncrement; angle = 0; stackSize = abs(size*sin(topAngle)); y = startParticle.pos[1] + size*(1 - cos(topAngle)); if (stack == nStacks - 1) { nSlices = 1; } else { nSlices = res; } for (int slice = 0; slice < nSlices; slice++) { allInBall[stack][slice] = new Particle(stackSize*sin(angle), y, stackSize*cos(angle)); ps.addParticle(allInBall[stack][slice]); angle += rotIncrement; } } for (int stack = 0; stack < nStacks - 1; stack++) { for (int slice = 0; slice < res; slice++) { ps.addSpring(allInBall[stack][slice],allInBall[stack][(slice+1)%res]); if (stack > 0) ps.addSpring(allInBall[stack][slice],allInBall[stack-1][slice]); } } for (int slice = 0; slice < res; slice++) { ps.addSpring(startParticle,allInBall[0][slice]); ps.addSpring(allInBall[nStacks-2][slice],allInBall[nStacks-1][0]); } }