Skip to content

Instantly share code, notes, and snippets.

@rlieberman
Created November 17, 2014 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlieberman/25da545e5dbc66fcb745 to your computer and use it in GitHub Desktop.
Save rlieberman/25da545e5dbc66fcb745 to your computer and use it in GitHub Desktop.
sunsets_get_v5
void setup() {
size (400, 300); // make a canvas that's 300 x 300
//SETTING UP MY UNDERLYING GRID STRUCTURE
int numImages = 12;
int colWidth = 10; //column width
int rowHeight = 10; //row height
int colNum = width/colWidth;
int rowNum = height/rowHeight;
//FIRST LOAD ALL THE ORIGINAL IMAGES INTO AN ARRAY (BUT DON'T DRAW THEM)
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
StringList filelist = new StringList();
for (String s : names) {
if (!s.contains("DS_Store")) {
filelist.append(s);
}
}
return filelist.array();
} else {
// If it's not a directory
return null;
}
}
PImage[] sunsets = new PImage [filenames.length]; //make an array called sunsets of 9 images
for (int i=0; i<sunsets.length; i++) {
sunsets[i] = loadImage (filenames[i]); //load image
sunsets[i].resize(width, height); //resize it to the size of the canvas
}
//MAKE TILES FROM EACH IMAGE AND LOAD THEM INTO A NEW ARRAY
int tileX = colWidth;
int tileY = rowHeight;
//PImage[] tiles = new PImage [numImages]; //an array of tiles
// for (int i=0; i<sunsets.length; i++) { //making a tile for each image in the original sunsets array
// tiles[i] =sunsets[i].get(tileX*i, tileY*i, colWidth, rowHeight);
// image(tiles[i], tileX*i, tileY*i);
// }
int counter = 0; //start at first photo
for (int j = 0; j < rowNum; j++) { //loop through rows
for (int i = 0; i < colNum; i++) { //loop through columns
//int r = int(random(numImages));
PImage tile=sunsets[counter].get(i*colWidth, j*rowHeight, colWidth, rowHeight);
image(tile, i*colWidth, j*rowHeight);
stroke(0, 255, 0);
noFill();
// rect(i*colWidth, j*rowHeight,colWidth, rowHeight);
counter++;
if (counter >= sunsets.length) {
counter = 0;
} //value of counter never exceeds amt of images in the array
//println(i, j, counter);
}
}
}
void draw() {
noLoop();
}
// //TILE 0 (ROW 1)
// PImage sunsetTile0 = sunsets[0].get(0, 0, colWidth, rowHeight);
// image (sunsetTile0, 0, 0);
// //TILE 1 (ROW 1)
// PImage sunsetTile1 = sunsets[1].get(tileX, 0, colWidth, rowHeight);
// image (sunsetTile1, tileX, 0);
// //TILE 2 (ROW 1)
// PImage sunsetTile2 = sunsets[2].get(tileX*2, 0, colWidth, rowHeight);
// image (sunsetTile2, tileX*2, 0);
// //TILE 3 (ROW 1)
// PImage sunsetTile3 = sunsets[3].get(tileX*3, 0, colWidth, rowHeight);
// image (sunsetTile3, tileX*3, 0);
// //TILE 4 (ROW 2)
// PImage sunsetTile4 = sunsets[4].get(0, tileY, colWidth, rowHeight);
// image (sunsetTile4, 0, tileY);
// // TILE 5 (ROW 2)
// PImage sunsetTile5 = sunsets[5].get(tileX, tileY, colWidth, rowHeight);
// image (sunsetTile5, tileX, tileY);
// //TILE 6 (ROW 2)
// PImage sunsetTile6 = sunsets[6].get(tileX*2, tileY, colWidth, rowHeight);
// image (sunsetTile6, tileX*2, tileY);
// //TILE 7 (ROW 2)
// PImage sunsetTile7 = sunsets[7].get(tileX*3, tileY, colWidth, rowHeight);
// image (sunsetTile7, tileX*3, tileY);
// //TILE 8 (ROW 3)
// PImage sunsetTile8 = sunsets[8].get(0, tileY*2, colWidth, rowHeight);
// image (sunsetTile8, 0, tileY*2);
// //TILE 9 (ROW 3)
// PImage sunsetTile9 = sunsets[9].get(tileX, tileY*2, colWidth, rowHeight);
// image (sunsetTile9, tileX, tileY*2);
// //TILE 10 (ROW 3)
// PImage sunsetTile10 = sunsets[10].get(tileX*2, tileY*2, colWidth, rowHeight);
// image (sunsetTile10, tileX*2, tileY*2);
// //TITLE 11 (ROW 3)
// PImage sunsetTile11 = sunsets[11].get(tileX*3, tileY*2, colWidth, rowHeight);
// image (sunsetTile11, tileX*3, tileY*2);
// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
} else {
// If it's not a directory
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment