I have added a basic bouncing procedure which works indepedently of the mouse
The idea is to have a parameter which maintains the x,y,z location and when the other sketch loads is starts from that point, and the transition will be smooth.
Quote:import java.lang.reflect.Constructor;
public boolean forward = true;
public boolean up = false;
public int px=0;
public int py =0;
public int ly=0;
public int lx=0;
final int W = 640, H = 480, BG = #000000, fps = 30, seconds = 6;
boolean export = true;
PApplet[] sketches;
String[] names;
int s;
void setup() {
size(W, H);
Class[] classes = getClass().getDeclaredClasses();
int n = classes.length;
sketches = new PApplet[n];
names = new String[n];
for(int i=0; i<n; i++) {
try {
Constructor c = classes[i].getDeclaredConstructor(getClass());
sketches[i] = (PApplet) c.newInstance(this);
sketches[i].init();
names[i] = split(c.getName(), "$")[1];
} catch (Exception e) {}
}
frameRate(fps);
}
void draw() {
bounce(true, 3, 1, 5);
if(frameCount % (seconds * fps) == 1) {
// stop running sketch
if(frameCount>1) {
println("stopping " + names[s]);
sketches[s].stop();
s = (s+1) % sketches.length;
}
// start next sketch
println("starting " + names[s]);
sketches[s].run();
}
sketches[s].handleDraw();
PImage img = sketches[s].get();
img.loadPixels();
image(img, 0, 0);
if(export && frameCount <= fps*seconds*sketches.length) saveFrame("showreel-#####.png");
}
class Sketch1 extends PApplet {
void setup() {
size(W, H,JAVA2D);
smooth();
}
void draw() {
background(BG);
ellipse(px, py, 20, 20);
}
}
class Sketch2 extends PApplet {
void setup() {
size(W, H, JAVA2D);
smooth();
}
void draw() {
background(BG);
// ellipse(W/2, H/2, 20, 20);
ellipse(px, py, 20, 20);
}
}
class Sketch3 extends PApplet {
void setup() {
size(W, H, P3D);
smooth();
}
void draw() {
background(BG);
lights();
noStroke();
// translate(W/2, H/2, 0);
translate(px,py, 0);
sphere(10);
}
}
void bounce(boolean rnd, int by, int lo, int hi){
if (forward){
if (rnd)px+=random(lo,hi);
if (!rnd){
px+=by;
}
}
if (!forward){
if(rnd)px-=random(lo,hi);
if (!rnd){
px-=by;
}
}
if (up){
if (rnd)py-=random(lo,hi*2);
if (!rnd){
py+=by;
}
}
if (!up){
if(rnd)py+=random(lo,hi*2);
if (!rnd){
py-=by;
}
}
if (px>width)forward = false;
if (px<0) forward = true;
if (py>height)up = true;
if (py<0 )up = false;
}