How to make a random image appear without giving a person a seizure?

hI, I'm trying to get it so when you move your mouse to a certain area a picture will show up, and in some areas a different image will show up when you move in and out of that specific area. I've been using the random() to get different images, but when I do, and I hover over that specified area, it flashes through all the pictures really fast, fast enough to give someone an epileptic seizure. reducing the frame rate helps, but gives it a jerky visuals. I've used mouseMoved() as well, but again jerky. I could use mousePressed, but I really wanted to have the mouse sort of "hover" in that area to get an image. Here's my code (ignore the fact that no one else has my images). any thoughts? my assignment is due in ....11 hours....but still, I would appreciate any help.``

PFont f;
PImage metro;
PImage [] myboughArray = new PImage [2];
PImage [] mypetalArray = new PImage [2];
PImage [] myapparitionArray = new PImage [3];

PImage petal0;
PImage apparition1;
PImage bough0;
PImage apparition2;
PImage apparition0;
PImage bough1;
PImage petal1;
PImage wetblack;

void setup() {
  size (1000,600);
  //frameRate(50);
  f = loadFont ("TimesNewRomanPS-BoldMT-48.vlw");
  textFont (f, 34);
  metro = loadImage("metro.jpg");
  image (metro, 0,0, width, height);
  petal1 = loadImage("petal1.jpg");
  image (petal1, 0, 0, width, height);
  petal1.resize (1000, 0);
  petal0 = loadImage ("petal0.jpg");
  image (petal0, 0, 0, width, height);
  petal0.resize (1000, 0);
  apparition1 = loadImage("apparition1.jpg");
  image (apparition1, 0,0, width, height);
  apparition1.resize (1000,0);
  bough1 = loadImage("bough1.jpg");
  image(bough1, 0, 0, width, height);
  bough0 = loadImage("bough0.jpg");
  bough0.resize (1000,0);
  apparition2 = loadImage("apparition2.jpg");
  image (apparition2, 0, 0, width, height);
  apparition2.resize (1000,0);
  apparition0 = loadImage ("apparition0.jpg");
  image (apparition0, 0, 0, width, height);
  apparition0.resize (1000, 0);
  wetblack = loadImage ("wet,black.jpg");
  image (wetblack, 0, 0, width, height);
  wetblack.resize (1000,0);
  background (255);

  for (int i=0; i< myboughArray.length; i++){
    myboughArray [i]= loadImage ("bough" +i+ ".jpg");
  }
  for (int k=0; k<mypetalArray.length; k++){
    mypetalArray [k] = loadImage ("petal" +k+".jpg");
  }
  for (int m=0; m<myapparitionArray.length; m++){
    myapparitionArray [m] = loadImage ("apparition" +m+ ".jpg");
  } 

}

void draw() {
  //println(mouseX+ ","+ mouseY);

  if (mouseX>= 50 && mouseX <= 500 && 
      mouseY>= 0 && mouseY<= 350){
      image (metro, 0, 0);
  } else {
    background(255);
  }
  if (mouseX>= 265 && mouseX <= 335 && 
      mouseY>= 340 && mouseY<= 380) {

        image (mypetalArray[(int)random(2)], 0, 0);
      }

  if (mouseX>= 300 && mouseX <= 440 && 
      mouseY>= 290 && mouseY<= 335) {
       //for (int t =0; t<
        image (myapparitionArray[(int)random(3)], 0, 0);
      }
  if (mouseX>= 500 && mouseX <= 950 && 
      mouseY>= 300 && mouseY<= 550){
       image ( bough0,0, 0);
      }
  if (mouseX>= 500 && mouseX <= 600 && 
      mouseY>= 340 && mouseY<= 380) {
       image (myboughArray[(int)random(2)], 0, 0);
      }
  if (mouseX>= 400 && mouseX <= 500 &&
      mouseY>= 340 && mouseY <= 380) {
        image (wetblack, 0, 0);
      }
}
Tagged:

Comments

  • edited February 2015

    the idea is to generate a random number only once when the mouse enters the field

    the random number gets stored in a variable that is used then as an index as long as the mouse is inside your field

    Chrisir ;-)

  • are you saying I should make another forloop or should I put the random function in the forloop in my setup? how would I do that? i keep getting a cannot convert float into int error

  • a for-loop? No.

    instead of

    image (mypetalArray[(int)random(2)], 0, 0);

    say

    image (mypetalArray[mypetalArrayIndex], 0, 0);

    first time the mouse goes in the field say once

    mypetalArrayIndex=(int)random(2);

    the trick is ... first time... and ... once...

    to determine that, you need to have a var telling you if it is the first time for each field...

    ;-)

Sign In or Register to comment.