Here is a more advanced example using the built-in mouseDragged -- it also saves a collection of previously drawn lines as children of a PShape, then displays the collection of past lines in the draw loop.
If you wanted specifying lines to be based on a two-point clicking rather than dragging, you would need a state variable like an int to track which state you were in -- click the first point, click the second, or click again to save / clear, then click the first point....
Answers
In the Processing's website under reference, you can check the following key words: mousePressed() and mouseReleased(). Sample code below.
Kf
Start position:
End position:
Show it:
Here is a more advanced example using the built-in mouseDragged -- it also saves a collection of previously drawn lines as children of a PShape, then displays the collection of past lines in the draw loop.
If you wanted specifying lines to be based on a two-point clicking rather than dragging, you would need a state variable like an int to track which state you were in -- click the first point, click the second, or click again to save / clear, then click the first point....