I am trying to draw at one place by dragging a mouse (for example, a circle in left upper quadrant) and have the figure appear at 4 places around center of canvas (including one right under the mouse cursor). I have tried following code:
int x=0;
int y=0;
void setup(){
size(400, 400);
background(255);
translate(width/2, height/2);
}
void draw() {
}
void mouseDragged(){
translate(width/2, height/2);
for(int i=0; i<4; i++){
rotate(PI/2);
x= mouseX ; y=mouseY;
line(x, y, mouseX, mouseY);
}
}
However, the figure does not get drawn under the mouse cursor. If I am very close to upper left corner, the lines get drawn at center of canvas.
Secondly, a total of 5 figures get drawn instead of 4 as I am trying. If I draw near left upper corner, the unwanted figure appears at right lower corner of canvas. This unwanted figure is fainter than other figures.
Where are the errors and how can both these problems be corrected? I want to achieve this with rotate commands (rotating around center of canvas), though I saw that I can also use translate command to draw at 4 places on canvas.
Thanks for your help.