I am trying to draw straight lines (in processing 3.5.4) like it is done in MS Paint tool (select a point by clicking the left mouse button and drag the pointer before releasing it to get the straight line). I have tried using mousePressed()
and mouseReleased()
functions and it creates the straight line but it does not show the straight line in real-time when I drag it without releasing it, which is normal given I've not used draw()
function in this case.
void mousePressed() {
x1 = mouseX;
y1 = mouseY;
}
void mouseReleased() {
line (x1, y1, mouseX, mouseY);
}
I have also tried to implement creating the line inside the draw()
function so that I can get the real-time movement of the unreleased straight line but this also fails by drawing multiple straight lines.
void draw () {
if(mousePressed) {
line (x1, y1, mouseX, mouseY);
}
}
I've marked (x1
, y1
) and (mouseX
, mouseY
) points as mouse's pressing and releasing points
And I am trying to achieve something like this (while dragging the mouse) on real-time.
I've marked the points for the understanding purpose