PSystem ps; Arcball arcball; class RectParticle extends Particle { public RectParticle() {} void draw() { push(); translate(pos[0], pos[1], pos[2]); if (this == magnetParticle) { fill(#00FF00); } else if (fixed()) { fill(#FF0000); } else { fill(100); } box(5, 5, 5); pop(); } } int PARTICLES_Z = 5; int PARTICLES_Y = 4; int PARTICLES_X = 10; float unitLength = 30; Particle magnetParticle; Particle[][][] particles; void setup() { size(500,500); ps = (PSystem)loadPlugin("PSystem"); arcball = (Arcball)loadPlugin("Arcball"); ps.setGravity(0); translate(width/4, height/2); ps.defaultSpringRestLength = unitLength; ps.defaultSpringStrength = 1; 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(); magnetParticle = particles[2][2][2]; Magnet m = ps.addMagnet(magnetParticle); m.strength = -2; } void makeGrid() { particles = new RectParticle[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); if (x > 0) { ps.addSpring(particles[x][y][z], particles[x-1][y][z]); } if (y > 0) { ps.addSpring(particles[x][y][z], particles[x][y-1][z]); } if (z > 0) { ps.addSpring(particles[x][y][z], particles[x][y][z-1]); } } } } } void loop() { background(200); translate(width/4, height/2); arcball.run(); ps.draw(); }