I need help with my code in processing. It is actually a short and easy code, but I am a beginner in programming, so for me seems everything difficult... :(
My goal is... - to click on an image. - After the mouse click, the image should disappear - and show up in a new random position. - Then I should be able to click on the image in the new random position, - and it should do the same again: disappear and show up in a new random position. - and so on.
I have written some code (see below), but it does not work properly. I would really appreciate it if someone could help me to find out, what is wrong with my code. Thank you very much in advance! :)
Here is my code:
PImage pic;
// Declare variables for the picture
float pic_x;
float pic_y;
float pic_r = 100;
float pic_x_new = random(0, 400);
float pic_y_new = random(0, 400);
boolean mouseOverPic;
void setup(){
size(500,500);
background(0,100,0);
//loading the picture
pic = loadImage("pic.png");
image(pic, pic_x, pic_y, pic_r, pic_r);
}
void draw(){
mouseOverPic = mouseX <= pic.width
&& mouseX >= pic_x
&& mouseY <= pic.height
&& mouseY >= pic_y;
if (mousePressed && mouseOverPic) {
background(100);
image(pic, pic_x_new, pic_y_new, pic_r, pic_r);
}
}
Aucun commentaire:
Enregistrer un commentaire