We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello processing community, i'm new to programming(processing is the first thing i've tried). and I was having some problems with my code. I'm trying to make my background change every few seconds for a brief amount of time, but it just won't work, can you help me out? Thanks in advance :)
PImage bg;
PImage bg2;void setup() {
framerate(10);
size(720, 720);
bg = loadImage("bg.jpg");
bg2 = loadImage("bg22.jpg");
}
void draw() {
background(bg);
float X = random(60);
if(X == 1) {
background(bg2);
}
}
Answers
Welcome, @niekocaster .
Please edit your post and format the code: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
Try adding a print statement here to see what is happening with X:
Is X ever equal to 1? Why not?
random(60)
will create a random float between 0 and 60. Try to use println() to see what is going on.I modified your code a little, maybe that helps to understand why it is very unlikely, that you will ever see that condition become true.
So change the line 4 of benja's code to
int x = int(random(60))
and you'll notice the phenomenon becomes a lot more common.