PSystem ps; Arcball arcball; class RectParticle extends Particle { public RectParticle() {} void draw() { push(); stroke(100, 100, 100, 100); translate(pos[0], pos[1], pos[2]); if (fixed()) { fill(#FF0000); } else { fill(#DDDDDD); } box(5, 5, 5); pop(); } } int PARTICLES_Z = 5; int PARTICLES_Y = 4; int PARTICLES_X = 10; float unitLength = 30; Particle[][][] particles; void setup() { size(500, 500); ps = (PSystem)loadPlugin("PSystem"); arcball = (Arcball)loadPlugin("Arcball"); ps.setGravity(-0.3); ps.defaultSpringRestLength = unitLength; ps.defaultSpringStrength = 0.5; makeGrid(); particles[0][PARTICLES_Y-1][0].fix(); particles[PARTICLES_X-1][PARTICLES_Y-1][0].fix(); particles[0][PARTICLES_Y-1][PARTICLES_Z-1].fix(); particles[PARTICLES_X-1][PARTICLES_Y-1][PARTICLES_Z-1].fix(); } void loop() { translate(width/4, height/2); background(#99CCCC); arcball.run(); ps.draw(); } void makeGrid() { particles = new Particle[PARTICLES_X][PARTICLES_Y][PARTICLES_Z]; for (int x = 0; x < PARTICLES_X; x++) { for (int z = 0; z < PARTICLES_Z; z++) { for (int y = 0; y < PARTICLES_Y; y++) { particles[x][y][z] = new RectParticle(); ps.addParticle(particles[x][y][z]); particles[x][y][z].setPos(unitLength*x,unitLength*y,unitLength*z); // Don't add springs if x == 3 if (x != 3) { if (x > 0) { ps.addForce(new Spring(particles[x][y][z], particles[x-1][y][z])); } if (y > 0) { ps.addForce(new Spring(particles[x][y][z], particles[x][y-1][z])); } if (z > 0) { ps.addForce(new Spring(particles[x][y][z], particles[x][y][z-1])); } } } } } // Just add one spring for x == 3 ps.addForce(new Spring(particles[3][2][2], particles[2][2][2])); }