Displaying Random Images on a Certain XY


#1

Hi mankind, I need help. I am trying to make something like a slideshow.

I need to put an image on a certain xy coordinate
when i click to mouse image will randomly change, it will be hundreds of images,
and it will be some other image onto this randomly changing images, and they also will randomly change

Is there anybody in there?


#2

Hey janberkjk!

Be sure to post your code so we can take a closer look. Are you trying to add some interaction with the mouse? What exactly are you trying to do?


#3

Hi Nic,

I am sorry but i just start to learn and whatever i try i could’t get anything yet to show you. ı am still trying if i can find something close to what i want to write i will share, thank you for reply


#4

ı did something like this but it gives me float numbers =(

PImage foto;
int fotoname;
 
void setup(){
  size(1080,680);  
  fotoname = 1;
  
}

void draw(){

  image(loadImage (random(fotoname) + ".jpg"), 500, 330);
  fotoname=fotoname+1;
  
}

#5

To fix this, try int(random(fotoname)).


#6

Hello Again Nic, thank you very much. it is almost done. But i try to make bg image names between 6 and 9. but with this code, 1, 2, 3, 4, and 5.jpg are also displays as bgfoto, can you see why?

PImage foto;
PImage bg;
int fotoname;
int bgfoto;
 
void setup(){
  size(1080,680);  
  bgfoto = int(random(6,9));
  fotoname = (5);
  
  
}

void draw(){
  image(loadImage (int(random(bgfoto)) + ".jpg"), 0, 0, 1080, 680);
  image(loadImage (int(random(fotoname)) + ".jpg"), 200, 230,180,180);
  bgfoto=bgfoto;
  fotoname=fotoname;
  
}

#7

We run this, and for example bgfoto now equals “7”

Now what happens when we put the seven in here?

image(loadImage (int(random(7)) + ".jpg"), 0, 0, 1080, 680);

Because you used random again, we now get a number 0-6.

Don’t use random a second time!


#8

Thank you very much, now i can see the reason =) I changed the code a litlle bit and i created another topic about frame rates of this pictures.
Here is the code

void setup(){
  size(1080,680); 
  frameRate(1);
 
}

void draw(){
  println(frameRate);
  image(loadImage (7 + int( random( 3 ) ) + ".jpg"), 0, 0, 1080, 680);
  image(loadImage (int(random(5)) + ".jpg"), 200, 230,180,180);   
}

it is working very good but i cant apply different framerates for those photos.

What i want to see
first picture gruop will change in eigth seconds
second picture gruop will change very quicky like 6 in only one second.

We I couldnt understand under the other topic can you help me about it? Thanks again


#9

Please format the code in your posts: highlight + </> button.

Quick forum advice:

  • If you want help on a related topic, give a link to that topic.
  • If you have several related questions about one piece of code, keep everything in one topic.

frameRate is not for controlling the speed of individual elements – it controls the speed of the screen redraw.

Control the timing of element display by checking frameCount or millis()

For example:

void setup() {
  frameRate(4);
  noStroke();
}
void draw() {
  background(0);
  if (frameCount%16==0) {
    fill(255);
    rect(0, 0, width/4, height);
  }
  if (frameCount%12==0) {
    fill(255, 0, 0);
    rect(width/4, 0, width/4, height);
  }
  if (frameCount%8==0) {
    fill(0, 255, 0);
    rect(2 * width/4, 0, width/4, height);
  }
  if (frameCount%4==0) {
    fill(0, 0, 255);
    rect(3 * width/4, 0, width/4, height);
  }
}

#10

Wow dudu its perfect =) I finally figured it out. This framecount option is great. I do not understand forum rules i am sorry about it i actualy never understood =) i just have one question about this code and i am not sure if i ask here or open another topic. question is why at the beggining there is a gray bg. why image is not shown at the beggining? shoul i open another topic for it?

void setup(){
  size(1080,680); 
  frameRate(20);
  noStroke();
 
}

void draw(){
  if (frameCount%16==0) {
  image(loadImage (7 + int( random( 3 ) ) + ".jpg"), 0, 0, 1080, 680);
  }
  if (frameCount%1==0) {
  image(loadImage (int(random(5)) + ".jpg"), 200, 230,180,180);  
  }
}

#11

Please format the code in your posts: edit your post and highlight the code + </> button.


#12

Don’t open a new topic - keep related questions about the same code in the same thread.

This is because setup runs on frameCount == 0. Draw runs for the first time on frameCount == 1.

If you want something to happen on the very first draw frame, then repeat, use frameCount%n==1, where n is the number of frames in the cycle.


#13

Hi, Jeremy, i could not understand about highligting code issue, sorry. Your explaining metod of reasons is very good about codes, i think you should write a book. Thank you for your help so far.