The main problem here is that your while loops have no end condition.
The while loop will continue to loop while the statement is true;
For instance, let say that your CatGenerator is randomly initialised with the value of 2. The first while loop won’t execute because the condition isn’t true, then the second while loop will execute, saying that an image of a cat should be displayed at the top left corner. But because after that, the condition is still true, the loop will continue.
In fact, you shouldn’t be using while loops here, but ‘if’ statement. By the way, variable = value
will assign the value to your variable, while variable == value
will return the boolean corresponding to true if variable has this value, false if it doesn’t.
Also, one thing you should know is that what ask processing to be displayed is only displayed at the end of the draw() loop, so if you don’t have any nothing will be displayed.
One last thing, you are loading the images after telling processing to display them.
Here is something that should work
PImage cat1; //regular Cat
PImage cat2; //angry Cat
PImage cat3; //derpy Cat
float CatGenerator = random(1,3);
void setup() {
size(32,48);
cat1 = loadImage("regularcat.png");
cat2 = loadImage("angrycat.png");
cat3 = loadImage("derpycat.png");
//CatGenerator(); //CatGenerator isn't a function, so calling it will not help
//you have init it randomly already
}
void draw(){
background(0); //the background should be reseted before drawing the image
if(CatGenerator == 1) {
image(cat1,0,0);
}
else if(CatGenerator == 2) { //I added the else statements, but it is really not needed, you can stick with if statements only
image(cat2,0,0); //it is just to make less comparisons, because if the first condition is met, the others can't be true (same with the 2nd)
} //alternatively, you could use switch() but no need to over complicate.
else {
image(cat3,0,0);
}
//once the program has reached this portion of the code, it will draw everything and start the draw loop again.
//to avoid this never ending draw loop as you only need things to be drawned once, you can add noLoop(); in the setup function for instance.
}
if you want to have a new random picture each frame, you should add CatGenerator = random(1, 3); in the draw loop. Btw this is the reason I let cat1, cat2 and cat3 because if the program should only display one picture at each execution, the code can be shorten to that :
PImage cat; //you only need to load one of the three pictures
float CatGenerator = random(1,3);
void setup() {
size(32,48);
if(CatGenerator == 1) {
cat = loadImage("regularcat.png");
}
else if(CatGenerator == 2) {
cat = loadImage("angrycat.png");
}
else cat = loadImage("derpycat.png");
noLoop();
}
void draw(){
background(0); //the background should be reseted before drawing the image
image(cat, 0, 0);
}
I hope that helps!