Any ideas how to make this select a random image at mouseclick?
in
Programming Questions
•
1 year ago
PImage bgImage; // reserve some memory for images
int imageNumber = 0; // the number of the current image
int numberOfImages = 15; // the total number of images
void setup()
{
size(320,480);
//load the first image into the memory
bgImage = loadImage("Homepage.gif");
}
void draw()
{
//draw the image to the screen
image(bgImage, 0, 0,width, height);
}
// the function that runs when the mouse is pressed
void mousePressed()
{
// add 1 to the imageNumber to move onto the next image
imageNumber = imageNumber + 1;
// if the number goes above the total number of images
if (imageNumber >= numberOfImages)
{
// reset image number to one
imageNumber = 1;
}
//load the new image to the memory
bgImage = loadImage("iBlame" + imageNumber +".gif");
}
1