Created
August 28, 2012 13:21
-
-
Save cyrildiagne/3497910 to your computer and use it in GitHub Desktop.
Live Proce55ing gallery for Playtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.opengl.*; | |
File photoDir; | |
String photoPath = selectFolder(); | |
ArrayList imgs; | |
int refreshCount = 0; | |
int lastCount = 0; | |
float drawOffset = 0; | |
int numPhotoDisplayed = 4; | |
int timeBeforeRefresh = 15; | |
void setup() { | |
size(1280, 768, OPENGL); | |
frameRate(30); | |
photoDir = new File(photoPath); | |
imgs = new ArrayList(); | |
refresh(); | |
} | |
void removeDSStore() { | |
File dsStore = new File(photoPath+"/.DS_Store"); | |
if(dsStore.exists()) { | |
dsStore.delete(); | |
println("dsstore deleted"); | |
} else println("dsstore not found"); | |
} | |
void refresh() { | |
String[] files = photoDir.list(); | |
boolean bPhotoAdded = false; | |
if(files.length==0) return; | |
println(files.length); | |
while(files.length > lastCount) | |
{ | |
lastCount++; | |
if(files.length-lastCount >= numPhotoDisplayed) { | |
continue; | |
} | |
if(!files[lastCount-1].equals(".DS_Store") && !files[lastCount-1].equals(".com.apple.timemachine.supported")) { | |
println("new photo added "+files[lastCount-1]); | |
imgs.add(0, loadImage(photoPath + "/" + files[lastCount-1])); | |
bPhotoAdded = true; | |
drawOffset -= 1; | |
} | |
} | |
if(!bPhotoAdded) { | |
int rnd = (int)random(files.length); | |
if(!files[rnd].equals(".DS_Store") && !files[rnd].equals(".com.apple.timemachine.supported")) { | |
println("random photo added "+files[rnd]); | |
imgs.add(0, loadImage(photoPath + "/" + files[rnd])); | |
drawOffset -= 1; | |
} | |
} | |
while(imgs.size() > numPhotoDisplayed) { | |
imgs.remove(imgs.size()-1); | |
} | |
} | |
void draw() { | |
drawOffset += (0.0-drawOffset)*0.05; | |
refreshCount++; | |
if(refreshCount>=timeBeforeRefresh*30) { | |
refreshCount = 0; | |
refresh(); | |
} | |
PImage img; | |
for(int i=0; i<imgs.size(); i++) { | |
img = (PImage)imgs.get(i); | |
float ratio = (float)height/img.height; | |
image(img, (drawOffset+i)*(float)img.width*ratio, 0, img.width*ratio, height); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment