funtion to Load different set of Image-folder indifrent a arrays

edited March 2016 in Questions about Code

I will like to create a function that will loads images in an array. I have 10 different folders with different numbers of images, let’s call them folder1 to folder 10. all images will be naming the same 1.png to...... different for each one (let say for now 700)

I will like to load all the data this is where I have my problem now. - will need to be able to access image with Image - have a variable of the total amount of the image in a folder

In draw: I will choose randomly 1 folder and from that folder chose a random image between a range. Each draw will upgrade that range. 1st range: round( 0% to 1.4%) 2st range: round( 1.4% to 2.8%)

I know my code is not working I am missing some information counting all image and the array of images for each folder. hope i am near the solution.

import processing.pdf.*;

PImage frame[]; //image from the folder

int totalPage=96; //number of page
float page=1;  
float pageNow= 100*page/totalPage; //the last limit
float pageAdd= 100*1/totalPage; // time gape in a page
float pageBefor= pageNow-pageAdd; //the first limit


String [] MovieID; //name of the folder
int [] tFMovieID; //total image in folder
void setup() {
  size(840, 640);
  smooth();
  frameRate(1);

  MovieID = new String[10];
  MovieID[0] = "tt0063442"; // Planet of the Apes
  MovieID[1] = "tt0074812"; // Logan's Run
  MovieID[2] = "tt0089092"; // Enemy Mine
  MovieID[3] = "tt0114746"; // Twelve Monkeys 
  MovieID[4] = "tt0119177"; // Gattaca
  MovieID[5] = "tt0120907"; // eXistenZ
  MovieID[6] = "tt0212720"; // A.I. Artificial Intelligence 
  MovieID[7] = "tt1798709"; // Her
  MovieID[8] = "tt0816692"; //  Interstellar
  MovieID[9] = "tt0470752"; // ex-machina
  //Chappie  tt1823672

  tFMovieID= new int[10];
  tFMovieID[0] = MovieID[0] counting all image; // here i don't know 
  //....
  tFMovieID[9] = MovieID[9] counting all image; // here i don't know 
}

void draw() {
  beginRecord(PDF, "###.pdf");
  background(255);

int numberM= random(0,11);
totalframe= tFMovieID[numberM];
selecImage =  random ( totalframe*(pageBefor/100), totalframe*(pageNow/100));
 frame = loadImage(MovieID[numberM]+"/"+selecImage+".png");
image(frame, 100, 100);

  pageInfo();
  /*grid();
   pushMatrix();
   translate(400, 0 );
   grid();
   popMatrix();*/
  cutLine();

  endRecord();
  page=page+1;
  if (frameCount >totalPage) {
    exit();
  }
}
Tagged:

Answers

  • edited March 2016

    I am now trying to make a double array[][] to load my image the firs is the folder and the other is the image number.

    I imagine this is not the good technique because I have a null point exception.

    import processing.pdf.*;
    import java.io.File;
    java.io.File folder;
    
    
    
    int totalPage=96; //number of page
    float page=2;  
    float pageNow; //the last limit
    float pageAdd; // time gape in a page
    float pageBefor; //the first limit
    
    int numberM;
    String [] MovieID; //name of the folder
    int [] tFMovieID; //total image in folder
    PImage[][] frame;
    int numberFrame;
    int numberMovie;
    int[] x;
    int[] y;
    
    int selecImage;
    
    void setup() {
      size(840, 640);
      smooth();
      frameRate(1);
      MovieID = new String[2];
      //MovieID[0] = "tt0063442";// 2001 68
      // MovieID[1] = "tt0074812"; // Logan's Run 76
      // MovieID[3] = "tt0114746"; // Twelve Monkeys 95
      //MovieID[4] = "tt0119177"; // Gattaca 97
      //MovieID[5] = "tt0120907"; // eXistenZ  99
      MovieID[0] = "tt0212720"; // A.I. Artificial Intelligence  2001
      // MovieID[8] = "tt1823672"; // minority report 2002
      // MovieID[2] = "tt0089092";  // i robot  2004
      // MovieID[7] = "tt1798709"; // Her 2013
      MovieID[1] = "tt0470752"; // ex-machina 2014
    
    
      for (int i=0; i< MovieID.length; i++ ) {
        //folder = new java.io.File(dataPath(MovieID[i]+"/"));
        //String[] filenames = folder.list();
        //numberFrame=filenames.length-1;
        numberMovie=i;
        numberFrame= 60;
        frame=new PImage[numberMovie][numberFrame];
        for ( int i2 = 1; i2< frame.length; i2++ )
        {
          frame[i][i2] = loadImage(dataPath(MovieID[i]+"/"+i2+".png"));   
        }
      }
      x= new int[20];
      int moreX=0;
      for ( int i=0; i<x.length; i++ ) {
        x[i]=20+moreX;
        moreX=moreX+40;
      }
      y= new int[12];
      int moreY=0;
      for ( int i=0; i<y.length; i++ ) {
        y[i]=10+moreY;
        moreY=moreY+50;
      }
    }
    void draw() {
      beginRecord(PDF, "###.pdf");
      background(255);
      int numXPos= int(random(1, 14));
      int numYPos= int(random(1, 9));
      int numXImg= int(random(5, 10));
      choseFrame(x[numXPos], y[numYPos], x[numXImg]);
      grid();
      pushMatrix();
      translate(400, 0 );
      grid();
      popMatrix();//*/
      cutLine();
    
      endRecord();
    
    
      if (frameCount >totalPage) {
        exit();
      }
      page=page+1;
    }
    
    void choseFrame(float imageX, float imageY, float imageSizeX) {
      pageNow= 100*page/totalPage; //the last limit
      pageAdd= 100*1/totalPage; // time gape in a page
      pageBefor= pageNow-pageAdd; //the first limit
    
      selecImage = round ( random ( numberFrame*(pageBefor/100), numberFrame*(pageNow/100)));
      println(selecImage);
      int selecMovie= int(random(0, 2));
      println(selecMovie);
      PImage f =frame[0][selecImage];
      println(f);
      float imageSizeY= (imageSizeX*f.height)/f.width;
    
      image(f, imageX, imageY, imageSizeX, imageSizeY);
    }
    
Sign In or Register to comment.