import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; import netscape.javascript.*; import javax.comm.*; import javax.sound.midi.*; import javax.sound.midi.spi.*; import javax.sound.sampled.*; import javax.sound.sampled.spi.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.sax.*; import javax.xml.transform.stream.*; import org.xml.sax.*; import org.xml.sax.ext.*; import org.xml.sax.helpers.*; public class ParticleGrid extends BApplet {PSystem ps;
Arcball arcball;

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);
  ps.defaultSpringRestLength = unitLength;
  ps.defaultSpringStrength = 0.5f;
  
  
  makeGrid();
}

void loop() {
  translate(width/4, height/2);
  background(0xff99CCCC);
  translate(width/4, 0);
  arcball.run();
  translate(-width/4, 0);
  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 Particle();
        ps.addParticle(particles[x][y][z]);
        particles[x][y][z].setPos(unitLength*x,unitLength*y,unitLength*z);
      }
    }
  }
}
}