Hello,
I am a beginner in Processing, and I need help.
My question is: how to fix an object in a certain position(x,y)?
Here is the code I use. What I want is to take the first rectangle by pressing the 'a' key, move it with the mouse, and let it where it is. Then I want to take the second rectangle, move it, and let it where it is. And so on with the two next rectangles. I want to keep the possibility to reset the position of the rectangles when I want, and to control the position of each one independantly of each other.
It shouldn't be difficult, but I don't know how to do.
Thank you if somebody has the answer!
float x;
float y;
void setup() {
size (800,800);
smooth();
noStroke();
}
void draw(){
background(0);
x=mouseX -400;
y=mouseY -100;
fill(255);
//A rectangle
if (key == 'a' || key == 'A') {
rect(56+x, 42+y, 293, 61);
}
else {
rect (56,42,293,61);
}
//B rectangle
if (key == 'b' || key == 'B') {
rect(485+x, 42+y, 211, 61);
}
else {
rect(485, 42, 211, 61);
}
//C rectangle
if (key == 'c' || key == 'C') {
rect(358+x, 281+y, 119, 66);
}
else {
rect(358, 281, 119, 66);
}
//D rectangle
if (key == 'd' || key == 'D') {
rect(582+x, 355+y, 63, 118);
}
else {
rect(582, 355, 63, 118);
}
}
1