I am currently trying to record and playback the positions of all particles in a particle system. I understand the concept though I am having difficulty with the implementation. I can record into a single array though I have difficulty when approaching multiple arrays.
To help illustrate my desired goal, I have created a working version with only one array:
// Record_Mouse Example
ArrayList<PVector> list = new ArrayList<PVector>(); // for storing the vector of our mouse location
int frames; // count frames for our interpolation
boolean begin = false; // our introduction screen
boolean recording;
void setup() {
size(900, 600);
smooth();
}
void draw() {
background(100);
frames++;
// Introduction ----------------------
if (!begin){
noStroke();
fill(255);
text("click the mouse to create a loop", 20, 20, 200, 200);
fill(200);
ellipse(mouseX,mouseY,60,60);
}
// Recording ----------------------
if (recording && begin) {
fill(255, 0, 0);
ellipse(mouseX,mouseY,60,60);
list.add(new PVector(mouseX, mouseY)); // add the mouse vector to the array
}
// Playback ----------------------
else if (begin) {
PVector rec = list.get(frames%list.size());
fill(0, 255, 0);
ellipse(rec.x,rec.y,60,60);
}
}
void mousePressed() {
list.clear(); // clear the array
recording = true; // turn on recording
begin = true; // move past the introduction screen
}
void mouseReleased() {
recording = false; // turn off recording
}
The example I am working with is located here:
Particle[] p = new Particle[4];
boolean recording;
boolean begin = false;
void setup() {
size(900, 600);
smooth();
noStroke();
for (int i=0; i< p.length; i++) {
p[i] = new Particle();
p[i].myIndex = i;
}
}
void draw() {
background(100);
fill(255);
text("click the mouse to create a loop", 20, 20, 200, 200);
if (begin) {
if (recording) {
for (Particle pa : p) {
pa.bounceIfColliding();
pa.display();
pa.move();
// -------------------------------------- Recording Help Needed Here
// pa.record();
}
fill(255, 0, 0);
text("RECORDING", width-100, 25, 150, 100);
}
else if (!recording && begin) {
for (Particle pa : p) {
pa.display();
// -------------------------------------- Playback Help Needed Here