Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A sketch incorporating images saved in the sketch folder into a vertical timeline.
int year = 0;
int y = 0;
int spacing = 50;
PImage[] imgs = new PImage[11];
String[] dates= new String[11];
String[] desc = new String [11];
void setup(){
String path = sketchPath();
String[] filenames = listFileNames(path);
printArray(filenames);
for (int i = 0; i < imgs.length; i++) {
dates[i] = filenames[i].substring(0,4);
desc[i] = filenames[i];
print(dates[i] + " ");
}
for (int i = 0; i < imgs.length; i++) {
imgs[i] = loadImage(filenames[i]);
}
size(800,500);
background(0);
textSize(15);
fill(255,255,255);
for (int i = year; i<2018; i=i+25){
text(i, 10, y+25);
y = y + spacing;
}
}
void draw(){
}
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
} else {
return null;
}
}
void keyPressed(){
if (key == CODED) {
int x = 0;
y = 10;
if (keyCode==DOWN && year<1950){
year = year + 25;
y=0;
background(0);
fill(255,255,255);
for (int i = year; i<2018; i=i+25){
print(year + " ");
if(i<0) {
text(abs(i) + " BC", 10, y+25);
} else {
text(abs(i), 10, y+25);
}
x = x+25;
y = y +spacing;
}
}
if (keyCode == UP && year>-5000){
y=0;
year = year - 25;
background(0);
for (int i = year; i<2018; i=i+25){
print(year + " ");
if(i<0) {
text(abs(i) + " BC", 10, y+25);
} else {
text(abs(i), 10, y+25);
}
x = x+25;
y = y+spacing;
}
}
}
for (int i = 0; i < dates.length; i++){
// if (str(year).equals(dates[i])) {
if (int(dates[i]) >= year && int(dates[i]) < year+25) {
image(imgs[i],150,70);
textSize(15);
text(desc[i],100,50);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.