How to change the speed of random images?

I have gotten some code already but im still not sure how to change it for what i want I want to slow down the speed of the images being shown. If i could i would love to move away from the function mousePressed. If i could move to people not having to click and just working over where there mouse is that would be cool.

So question (in bullet form)

I want to slow the speed that the imgs apear

i want to use mouse over vrs mousePressed.

if there are some tutorials you want to link to or if you just want to show me some examples. I want to completely understand the code i use.

The code i have now:

PImage[] images = new PImage[22]; PImage img = new PImage(); float x; float y; int r;

void setup() { size(1000,1000); for (int i = 0; i < images.length; i ++) { images[i] = loadImage( i +".jpg"); } } void draw() { if(mousePressed) { for(int count = 0;count<20;count ++) { r=int(random(22)); image(images[r],mouseX,mouseY); } } }

Answers

  • edited October 2015

    Hi, not tested, as I have no pictures, but should draw a different random picture at mouseX, mouseY each 20 frames.

        PImage[] images = new PImage[22];
        PImage img = new PImage(); 
        float x; 
        float y; 
        int r;
    
            void setup() { 
            size(1000,1000); 
            for (int i = 0; i < images.length; i ++) { 
            images[i] = loadImage( i +".jpg"); 
            }
          }
            void draw() { 
            if (frameRate%20 == 0){
              r = int(random(22));
            }
            image(images[r],mouseX,mouseY); 
          }
    
  • that makes the photos apear slower but it only shows one random photo then its the same photo.

  • Try this code, I've used frameCount https://processing.org/reference/frameCount.html

    PImage[] images = new PImage[4];
    float x; 
    float y; 
    int r;
    
    void setup() { 
      size(1000, 1000); 
      for (int i = 0; i < images.length; i ++) { 
        images[i] = loadImage( i +".jpg");
      }
    }
    void draw() { 
      if (frameCount%20 == 0) {
        r = int(random(4));
      }
      image(images[r], mouseX, mouseY);
    }
    
Sign In or Register to comment.