From 5a24bea25606ab50628a7c2b5e1f550321672a86 Mon Sep 17 00:00:00 2001 From: Stan Le Punk Date: Sun, 4 May 2014 18:12:29 +0200 Subject: [PATCH 1/2] Revision B : add opening function --- pechakucha10x20/U_CheckFolder.pde | 113 ++++++++++++++++++++++ pechakucha10x20/pechakucha10x20.pde | 140 ---------------------------- 2 files changed, 113 insertions(+), 140 deletions(-) create mode 100644 pechakucha10x20/U_CheckFolder.pde delete mode 100644 pechakucha10x20/pechakucha10x20.pde diff --git a/pechakucha10x20/U_CheckFolder.pde b/pechakucha10x20/U_CheckFolder.pde new file mode 100644 index 0000000..8ad2aa1 --- /dev/null +++ b/pechakucha10x20/U_CheckFolder.pde @@ -0,0 +1,113 @@ +ArrayList imageFiles = new ArrayList(); +boolean folderIsSelected ; +int countSelection ; +String selectedPathFolder = ("") ; +// main void +//choice Folder +void choiceFolder() { + folderIsSelected = true ; + if(key =='o') selectFolder("Select a folder to process:", "folderSelected"); +} + + + +// check what's happen in the selected folder +void checkFolder() { + if(folderIsSelected && selectedPathFolder != ("") ) { + countSelection++ ; + imageFiles.clear() ; + String path = selectedPathFolder ; + + println("Listing info about all files in a directory and all subdirectories: "); + ArrayList allFiles = listFilesRecursive(path); + + String fileName = ""; + + for (int i = 0; i < allFiles.size(); i++) { + File f = (File) allFiles.get(i); + fileName = f.getName(); + //println("Name: " + filename); + //println("Full path: " + f.getAbsolutePath()); + //println("Is directory: " + f.isDirectory()); + + // Add it to the list if it's not a directory + if (f.isDirectory() == false) { + String lastThree = fileName.substring(fileName.length()-3, fileName.length()); + if (lastThree.equals("PNG") || lastThree.equals("png") || lastThree.equals("JPG") || lastThree.equals("jpg") || lastThree.equals("GIF") || lastThree.equals("gif")) { + imageFiles.add(f); + } + } + } + // show the info name file + for (int i = 0; i < imageFiles.size(); i++) { + File f = (File) imageFiles.get(i); + println("Name: " + f.getName()); + } + + // to don't loop with this void + folderIsSelected = false ; + } +} +// end main void + +//choice Folder +void folderSelected(File selection) { + if (selection == null) { + println("Window was closed or the user hit cancel."); + } else { + println("User selected " + selection.getAbsolutePath()); + selectedPathFolder = selection.getAbsolutePath() ; + folderIsSelected = true ; + } +} + +// 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; + } +} + +// This function returns all the files in a directory as an array of File objects +// This is useful if you want more info about the file +File[] listFiles(String dir) { + File file = new File(dir); + if (file.isDirectory()) { + File[] files = file.listFiles(); + return files; + } + else { + // If it's not a directory + return null; + } +} + +// Function to get a list ofall files in a directory and all subdirectories +ArrayList listFilesRecursive(String dir) { + ArrayList fileList = new ArrayList(); + recurseDir(fileList, dir); + return fileList; +} + +// Recursive function to traverse subdirectories +void recurseDir(ArrayList a, String dir) { + File file = new File(dir); + if (file.isDirectory()) { + // If you want to include directories in the list + a.add(file); + File[] subfiles = file.listFiles(); + for (int i = 0; i < subfiles.length; i++) { + // Call this function on all files in this directory + recurseDir(a, subfiles[i].getAbsolutePath()); + } + } + else { + a.add(file); + } +} diff --git a/pechakucha10x20/pechakucha10x20.pde b/pechakucha10x20/pechakucha10x20.pde deleted file mode 100644 index 7a60f8e..0000000 --- a/pechakucha10x20/pechakucha10x20.pde +++ /dev/null @@ -1,140 +0,0 @@ - -import java.io.File; - -boolean start = true; - -int lastSecond; -int thisImage = 0; - -ArrayList imageFiles = new ArrayList(); - -void setup() { - size(1024, 768); - - String path = sketchPath; - - println("\nListing info about all files in a directory and all subdirectories: "); - ArrayList allFiles = listFilesRecursive(path); - - String fileName = ""; - - for (int i = 0; i < allFiles.size(); i++) { - File f = (File) allFiles.get(i); - fileName = f.getName(); - //println("Name: " + filename); - //println("Full path: " + f.getAbsolutePath()); - //println("Is directory: " + f.isDirectory()); - - // Add it to the list if it's not a directory - if (f.isDirectory() == false) { - String lastThree = fileName.substring(fileName.length()-3, fileName.length()); - if (lastThree.equals("PNG") || - lastThree.equals("png") || - lastThree.equals("JPG") || - lastThree.equals("jpg") || - lastThree.equals("GIF") || - lastThree.equals("gif")) { - - imageFiles.add(f); - } - println(lastThree); - } - //println("Size: " + f.length()); - //String lastModified = new Date(f.lastModified()).toString(); - //println("Last Modified: " + lastModified); - println("-----------------------"); - } - - println("-----------------------"); - println("-----------------------"); - println("-----------------------"); - println("-----------------------"); - println("-----------------------"); - - for (int i = 0; i < imageFiles.size(); i++) { - File f = (File) imageFiles.get(i); - println("Name: " + f.getName()); - } - - lastSecond = second(); - - //line(0, 0, width, height); - //line(0, height, width, 0); - textAlign(CENTER); - background(255); - text("PRESS SPACEBAR TO START", width/2, height/2); -} - -PImage img; - -void draw() { - // Empty, but needed to keep listening for keys - if (start && lastSecond != second() && second() % 20 == 0) { - File f = (File) imageFiles.get(thisImage); - img = loadImage(f.getAbsolutePath()); - if (thisImage < imageFiles.size()-1) { - thisImage++; - } - image(img, 0, 0, width, height); - lastSecond = second(); - } -} - -void keyPressed() { - - if (key == ' ') { - start = true; - } -} - -// 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; - } -} - -// This function returns all the files in a directory as an array of File objects -// This is useful if you want more info about the file -File[] listFiles(String dir) { - File file = new File(dir); - if (file.isDirectory()) { - File[] files = file.listFiles(); - return files; - } - else { - // If it's not a directory - return null; - } -} - -// Function to get a list ofall files in a directory and all subdirectories -ArrayList listFilesRecursive(String dir) { - ArrayList fileList = new ArrayList(); - recurseDir(fileList, dir); - return fileList; -} - -// Recursive function to traverse subdirectories -void recurseDir(ArrayList a, String dir) { - File file = new File(dir); - if (file.isDirectory()) { - // If you want to include directories in the list - a.add(file); - File[] subfiles = file.listFiles(); - for (int i = 0; i < subfiles.length; i++) { - // Call this function on all files in this directory - recurseDir(a, subfiles[i].getAbsolutePath()); - } - } - else { - a.add(file); - } -} - From 2fc852a490af392bc20781bf55f0d979a387ef8d Mon Sep 17 00:00:00 2001 From: Stan Le Punk Date: Wed, 7 May 2014 22:27:46 +0200 Subject: [PATCH 2/2] revision AL : menu to add images and texts --- pechakucha10x20/pechakucha10x20.pde | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pechakucha10x20/pechakucha10x20.pde diff --git a/pechakucha10x20/pechakucha10x20.pde b/pechakucha10x20/pechakucha10x20.pde new file mode 100644 index 0000000..c23466d --- /dev/null +++ b/pechakucha10x20/pechakucha10x20.pde @@ -0,0 +1,51 @@ +// main source is from UCLA Arts Software Studio by Casey Reas +void setup() { + size(1024, 768); + lastSecond = second(); + instruction() ; +} + +PImage img; + +void draw() { + checkFolder() ; + showPictures() ; +} +void keyPressed() { + choiceFolder() ; +} + + + +// ANNEXE + + +int lastSecond; +int thisImage = 0; +int countRef ; + +void showPictures() { + if(countSelection != countRef) thisImage = 0 ; + // Empty, but needed to keep listening for keys + if (!folderIsSelected && selectedPathFolder != ("") && lastSecond != second() && second() % 2 == 0) { + File f = (File) imageFiles.get(thisImage); + img = loadImage(f.getAbsolutePath()); + if (thisImage < imageFiles.size()-1) { + thisImage++; + } + image(img, 0, 0, width, height); + lastSecond = second(); + } + countRef = countSelection ; +} + + +void instruction() { + textAlign(CENTER); + background(255); + fill(0) ; + text("PRESS 'O' TO SELECT FOLDER", width/2, height/2); +} + + +