Skip to content

Instantly share code, notes, and snippets.

@ahx
Created December 29, 2008 21:35
Show Gist options
  • Save ahx/41398 to your computer and use it in GitHub Desktop.
Save ahx/41398 to your computer and use it in GitHub Desktop.
// import fullscreen.*;
import processing.video.*;
MovieMaker mm;
// FullScreen fs;
PImage img;
PGraphics mask;
String[] images;
int imgIndex = 0;
int xOffset;
int pauseFrames = 53; // number of frames after each image
int pauseCountdown = pauseFrames;
// FIXME remove
boolean imageUpdated;
void setup() {
size(1440/2, 900/2);
// fullscreen
// fs = new FullScreen(this);
// fs.enter();
mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.SORENSON, MovieMaker.HIGH);
frameRate(31);
images = split("79gedreht.jpg IMG_0405.JPG IMG_0397.JPG IMG_0449.JPG IMG_0058.JPG IMG_0424.JPG IMG_0209.JPG IMG_0322.JPG IMG_0054.JPG", ' ');
loadImage();
}
void draw() {
background(0);
image(img, (width/2 - img.width) + xOffset, 0);
// alter offset after first image, otherwise there would be a 1px gap
if(xOffset > 0)
--xOffset;
// mask
mask.beginDraw();
mask.rect(0, 0, img.width - xOffset, mask.height);
mask.endDraw();
img.mask(mask);
// display mirrored
pushMatrix();
translate(width/2, 0);
scale(-1.0, 1.0);
image(img, -img.width + xOffset, 0);
popMatrix();
// work against flickering (bug?)
if(imageUpdated == true) {
fill(0);
rect(0, 0, width, height);
imageUpdated = false;
}
// pause
if(xOffset <= 0) {
pause();
}
mm.addFrame();
}
void pause() {
if(pauseCountdown < 24) {
tint(map(pauseCountdown, 1, pauseFrames - 24, 0, 255));
}
if(--pauseCountdown < 0) {
pauseCountdown = pauseFrames;
imgIndex++;
loadImage();
}
}
void loadImage() {
if(imgIndex >= images.length || imgIndex < 0) {
mm.finish();
exit();
imgIndex = 0;
}
// load image, resize and evtl. crop
img = loadImage("../images/" + images[imgIndex]);
img.resize(width, 0);
if(img.height > height)
img.resize(0, height);
mask = createGraphics(img.width, img.height, P2D);
// offset
tint(255);
xOffset = img.width;
imageUpdated = true;
}
void keyReleased() {
switch(keyCode) {
case 37: //arrow right
--imgIndex;
break;
case 39: //arrow left
case 32:
++imgIndex;
}
loadImage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment