having trouble with ending the drawing of the circle
in
Programming Questions
•
6 months ago
hi.
im trying to write this programme and im having trouble with when the mouse is released the rectangle is still following the mouse and having trouble with printing the text. plz help
here is my code
boolean first = true;
boolean second = false;
float x1, y1, x2, y2;
void setup() {
size(300, 300);
background(255);
textSize(24);
fill(0);
textAlign(CENTER);
}
void draw() {
background(255);
if ( first == false) {
//fill(0,0,250);
rect(x1, y1, mouseX, mouseY);
}
else if (second == true) {
fill(255, 0, 0);
rect(x1, y1, x2, y2);
}
}
void mousePressed() {
background(255);
second = true;
x1 = mouseX;
y1 = mouseY;
//record the first corner
first = false;
fill(0, 0, 255);
}
void mouseReleased() {
//record the second (opposing)corner
second = true;
x2= mouseX;
y2 = mouseY;
//draw the red rectangle and the ready for the next round
first = false;
fill(255, 0, 0);
//rect(x1,y1,x2,y2);
x2=0;
y2=0;
text(round(area(x1, y1, x2, y2)), width/2, height/2);
background(255);
}
float area(float x1, float y1, float x2, float y2) {
float a1 = (x2-x1);
float a2 = (y2-y1);
return sqrt(a1*a1+a2*a2);
}
1