xxxxxxxxxx
//________ ________ ________.______________
//\_____ \\______ \ / _____/| \_ _____/
// _(__ < | | \ / \ ___| || __)
// / \| ` \ \ \_\ \ || \
///______ /_______ / \______ /___|\___ /
// \/ \/ \/ \/
// _____ __
// / \ _____ | | __ ___________
// / \ / \\__ \ | |/ // __ \_ __ \
/// Y \/ __ \| <\ ___/| | \/
//\____|__ (____ /__|_ \\___ >__|
// \/ \/ \/ \/
//+Download the GifAnimation library
//+open mpo picture in preview and export it to two jpgs
//+start the sketch
//+select left picture
//+select right picture
//+press space bar to stop the motion
//+set the distance of the two pictures to the desired position with the arrow keys
//+press space to play again
//+set the speed with + and -
//+export as gif with s
import gifAnimation.*;
GifMaker gifExport;
PImage left, right;
int leftOrigin, rightOrigin = 0;
int leftHeight, rightHeight = 0;
boolean play = true;
int fps = 10;
boolean export = false;
int startExport = 0;
void setup()
{
size( 640, 360 );
smooth();
frameRate(fps);
gifExport = new GifMaker(this, "export.gif");
gifExport.setRepeat(0); // make it an "endless" animation
selectInput( "Select left image", "imageChosen" );
selectInput( "Select right image", "imageChosen" );
}
void draw()
{
if ( left != null && right != null)
{
if (play) {
image( left, leftOrigin -20, leftHeight-5, width+40, height+10);
if (frameCount % 2 != 0)
{
image( right, rightOrigin -20, rightHeight -5, width +40, height +10);
}
println(frameRate);
if (export) {
gifExport.addFrame();
if (frameCount == startExport +2)
{
gifExport.finish();
exit();
}
}
} else {
image( left, leftOrigin -20, leftHeight -5, width+40, height+10);
tint(255, 126);
image( right, rightOrigin -20, rightHeight -5, width +40, height +10);
}
}
}
void imageChosen( File f )
{
if ( f.exists() && left == null )
{
left = loadImage( f.getAbsolutePath() );
} else if ( f.exists() && left != null ) {
right = loadImage( f.getAbsolutePath() );
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == RIGHT) {
leftOrigin -= 1;
rightOrigin += 1;
} else if (keyCode == LEFT) {
leftOrigin += 1;
rightOrigin -= 1;
} else if (keyCode == UP) {
leftHeight -= 1;
rightHeight += 1;
} else if (keyCode == DOWN) {
leftHeight += 1;
rightHeight -= 1;
}
} else if (key == ' ') {
play = ! play;
noTint();
} else if (key == '+') {
if (fps < 40) {
fps +=1;
}
frameRate(fps);
} else if (key == '-') {
if (fps > 1) {
fps -=1;
}
frameRate(fps);
} else if (key == 's') {
int Delay ;
Delay = int((1/frameRate)*1000);
gifExport.setDelay(Delay);
export = true;
startExport = frameCount;
}
}