Random images speed to change varyingly, not accordingly to frameRate.

Hello, sorry if the question title is a bit off. Here is my code which basically loads 200 random images from my folder and makes them pour like the matrix code :), they all change randomly within as well. But as you can see from the loop in draw they all change at the same time according to the frameRate but I want them to change randomly in varying speeds, sometimes even stop too. I feel like this can be managed via frameCount but couldn't figure out how exactly - did some research on it as well but couldn't find any. Thank you in advance.

    PImage[] myImageArray = new PImage[200];
    float px;
    float py; 
    float pz;

    void setup() {

      size(1920, 1080,P3D);
      frameRate(15);
      background(0);

      for (int i = 0; i < myImageArray.length; ++i) {
        (myImageArray[i] = loadImage("frag_" + i + ".jpg")).resize(0, 45);
      }
    }

    void draw() {

      background(0);
      pushMatrix();
      translate(px, py, pz);
      py+=5; // Glitch skip
      //pz-=5; // For zoom out
      for (int i=-2000; i<width; i+=125) {
        for (int j=-3000; j<3000; j+=95) {
        //for (int j=0; j<3000; j+=25) { // For glitch effect
         imageMode(CENTER);
         image(myImageArray[(int)random(200)], i, j);
         }
      } 
      popMatrix(); 
    }

Answers

  • edited January 2018

    I want them to change randomly in varying speeds

    Try making each of your images to have their own speed and update their position.

  • Thanks for the reply, I think I described what I'm aiming in a wrong way, sorry! I can make each column move downwards with different speeds but what I want is a bit different; you know when you use random() it updates it according to the frameRate, therefore here, in every frame a random image from the array is loaded but they are all changing at the same time in same speed. But I'm wondering how can I make them all change randomly in varying speeds as if each image has a different frameRate.

  • how can I make them all change randomly in varying speeds

    Do you want each column to fall at different speed keeping their distance or just different speed for each images perhaps like a rainfall?

  • Not exactly, I already have every row and column moving downwards at same speed and it also maintains the distance between the images (this is stated in the 2 for loops in draw, 125 and 95 in x and y) Also they are all moving downwards at same speed with py+=5. So far so good actually.

    Additionally what I want to change is this; you can see in 'draw' the random function changes the images as they move, so they all change at the exact same speed according to frameRate - for example if the frameRate would be 10 all the images would change 10 times per second. But I want all of them to be changing randomly in random speeds if that makes sense :) As if each image has it's own frameRate to change randomly.

    Sorry if this sounds a bit unclear, really couldn't know how to describe it in a better way..

    Thanks so much.

  • But I want all of them to be changing randomly in random speeds

    The word "them" is your problem -- in order for there to be an addressable entity that has a separate change speed, the easiest thing is to:

    1. Create a Faller class
    2. Create a class framerate property
    3. initialize that property randomly when you create each Faller.
    4. In draw, loop through an array / array list of Fallers, update them, and draw them. The object update will change the location and check the framerate before changing the image.

    See the objects and classes tutorial and examples:

  • Hello, thanks very much for answer. I'm trying to do this right now, somewhat the notification for this answer slipped from my eyes!!

  • @unknownplayer -- good luck. Follow up if you have questions.

    Note that you can model rate of change in several ways -- two examples:

    1. The rate variable is a modulo frameCount (rate=2 changes every other frame, rate=4 changes every 4th frame, etc.)
    2. a millisecond measure (a Faller has a changeRate time in milliseconds and a lastChanged time -- if the current time is > lastChanged+changeRate, change the Faller and update lastChanged.

    Each model has different properties -- for example, the first method allows you to increase or decrease the framerate, speeding up or slowing down all changes in the sketch -- 60fps will run twice as fast as 30fps. The second method is the opposite -- you can change the fps up or down, and changes will (more or less) still run at rate-independent constant speeds.

Sign In or Register to comment.