Skip to content

Instantly share code, notes, and snippets.

@murilopolese
Last active May 17, 2017 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murilopolese/b789c583f3372e5ac2917030fae181f7 to your computer and use it in GitHub Desktop.
Save murilopolese/b789c583f3372e5ac2917030fae181f7 to your computer and use it in GitHub Desktop.
Sprite Generator
import java.util.Arrays;
ArrayList<PImage> images = new ArrayList();
int columns = 12;
int rows = 12;
void setup(){
selectFolder("Select a folder to process:", "folderSelected");
}
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
loadImages(selection.getAbsolutePath());
}
}
void loadImages(String path) {
File dir = new File(path);
String[] list = dir.list();
Arrays.sort(list);
if (list == null) {
println("Folder does not exist or cannot be accessed.");
}
else {
for(int i = 0; i < list.length; i++) {
if(list[i].indexOf(".") != 0) {
images.add(loadImage(path + "/" + list[i]));
}
}
createOutputImage();
}
}
void createOutputImage() {
PGraphics output = createGraphics(
images.get(0).width*columns,
images.get(0).height*rows
);
output.beginDraw();
for(int i = 0; i < columns; i++) {
for(int j = 0; j < rows; j++) {
output.image(
images.get(i+(12*j)),
i*images.get(0).width,
j*images.get(0).height
);
}
}
output.endDraw();
output.save("export.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment