Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.List;
- import java.io.FileFilter;
- import java.io.FilenameFilter;
- import processing.pdf.*;
- boolean record;
- final int len=25;
- final int NMAX=10;
- PImage pic;
- ArrayList<PImage> imgContainer;
- int n=NMAX;
- int value = 250;
- float resizeX, resizeY;
- void setup() {
- size(800, 800, FX2D);
- resizeX=0.4;
- resizeY=0.4;
- imageMode(CENTER);
- colorMode(RGB, 255);
- background(250, 250, 250);
- rectMode(CENTER);
- //imageMode(CENTER);
- pic=loadImage("hand.jpg");
- pic.resize(width, height);
- //c1 = color(200, 25, 25);
- //c2 = color(25, 255, 200);
- loadAllMiniImages();
- println("It has been chosen to work with "+n+" images. Check="+imgContainer.size());
- noLoop();
- noStroke();
- }
- void draw() {
- background(200);
- pic.loadPixels();
- for (int y = 0; y < height; y+=24) {
- for (int x = 0; x < width; x+=24) {
- int index=y*width+x;
- color pixelValue = pic.pixels[index];
- color rgb = pixelValue;
- int r = (rgb >> 16) & 0xFF; // Faster way of getting red(argb)
- int g = (rgb >> 8) & 0xFF; // Faster way of getting green(argb)
- int b = rgb & 0xFF;
- //How far is the current color from white
- float dista=dist(r, g, b, 255, 255, 255);
- //50 is a threshold value allowing close to white being identified as white
- //This value needs to be adjusted based on your actual background color
- //Next block is processed only if the pixel not white
- if (dista>0) {
- float pixelBrightness = brightness(pixelValue);
- int imgPicked=(int)random(n);
- PImage selected=imgContainer.get((int)imgPicked);
- PImage acopy=selected.get();
- int val1=(int)(acopy.width*resizeX);
- int val2=(int)(acopy.height*resizeY);
- if (val1>1 || val2>1) {
- acopy.resize(val1,val2);
- }
- pushMatrix();
- float rotZ = radians(random(360)); //float rotZ = map(mouseX,0,width,0,TWO_PI); //USE this for a different effect
- translate(x,y);
- rotate(rotZ);
- image(acopy,0,0);
- popMatrix();
- }
- }
- }
- }
- void keyPressed() {
- if (keyCode==UP) {
- resizeX+=0.05;
- resizeY+=0.05;
- }
- if (keyCode==DOWN) {
- resizeX-=0.05;
- resizeY-=0.05;
- }
- resizeX=constrain(resizeX, 0, 1.5);
- resizeY=constrain(resizeY, 0, 1.5);
- surface.setTitle("Size= "+resizeX);
- redraw();
- }
- void mouseReleased() {
- redraw();
- saveFrame();
- }
- final FileFilter FOLDER_FILTER = new FileFilter() {
- @ Override boolean accept(final File path) {
- return path.isDirectory();
- }
- };
- final FilenameFilter PIC_FILTER = new FilenameFilter() {
- final String[] exts = {
- ".png" //, ".jpg", ".jpeg", ".gif"
- };
- @ Override boolean accept(final File path, String name) {
- name = name.toLowerCase();
- for (final String ext : exts) if (name.endsWith(ext)) return true;
- return false;
- }
- };
- void loadAllMiniImages() {
- File dataFolder = dataFile("image_segments");
- File[] imgDirs = dataFolder.listFiles(FOLDER_FILTER);
- imgDirs = (File[]) append(imgDirs, dataFolder);
- println(imgDirs.length, "folders found:");
- printArray(imgDirs);
- List<File[]> imgPaths = new ArrayList<File[]>();
- for (File dir : imgDirs) imgPaths.add(dir.listFiles(PIC_FILTER));
- println("\nImage paths found for all folders:");
- int totalLength = 0;
- for (File[] paths : imgPaths) {
- totalLength += paths.length;
- println();
- //printArray(paths);
- }
- println("Total images found in all subfolders:", totalLength);
- //NOW only process up to NMAX images if there are more than NMAX images.
- //Otherwise only use the images available.
- if (totalLength>NMAX) {
- n=NMAX;
- } else {
- n=totalLength;
- }
- imgContainer=new ArrayList<PImage>();
- int ctr=0;
- for (File[] paths : imgPaths) {
- for (File f : paths) {
- PImage pimg1=loadImage(f.getPath());
- println("["+ctr+"] "+f.getPath()+" Dimensions="+pimg1.width+"x"+pimg1.height);
- imgContainer.add(pimg1);
- ctr++;
- //Only load 50 images
- if (ctr==n)
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement