Display a random image on key press? Help!?
in
Programming Questions
•
1 year ago
Okay, so I'm in a beginner programming class and I really have no idea what I'm doing. So, if someone could help me with this code, I would be forever grateful.
So basically, what's supposed to happen is that it starts out with a photograph of a face, and when you press a number on the keyboard (from 1-6), a piece of the face will be replaced by another persons face. So basically all I need to know is how to get the images that are right now called "1/1.jpg" "2/1.jpg" etc, to select a random image from the specified folder. The folders are just labeled 1 - 6, and I can give the pictures different names if necessary. Yeah, so here's the code I have right now:
- PImage face;
- PImage a;
- PImage b;
- PImage c;
- PImage d;
- PImage e;
- PImage f;
- void setup() {
- size (1280, 800);
- face = loadImage("background.jpg");
- background(face);
- }
- void draw(){
- if(key=='1'){
- a = loadImage("1/1.jpg");
- image(a,0,0);
- }
- if(key=='2'){
- b = loadImage("2/1.jpg");
- image(b,640,0);
- }
- if(key=='3'){
- c = loadImage("3/1.jpg");
- image(c,0,266);
- }
- if(key=='4'){
- d = loadImage("4/1.jpg");
- image(d,640,266);
- }
- if(key=='5'){
- e = loadImage("5/1.jpg");
- image(e,0,532);
- }
- if(key=='6'){
- f = loadImage("6/1.jpg");
- image(f,640,532);
- }
- }
So yeah, how would I make the images random?
1