We are about to switch to a new forum software. Until then we have removed the registration on this forum.
this is the question:
Write a program that allows the user to click in 2 locations to draw a blue rectangle (where the 2 points you clicked on serve as the opposite diagonal corners).
what do you want? for us to do this for you?
(be careful how you answer)
try writing it in english first like:
// some global vars to store clicked position
//a boolean as a flag?
//// clear bg
//// if triggered
////// calc rect function parameters using both cordinates you got
////// with default rectMode they are (x_pos, y_pos, width, height)
//////so first two are first stored cordinates, 3rd and 4th, an easy calc away
////// set style
////// do draw a rect using the cordinates
////store clicked positions (mouseX, mouseY)
////first click first store slot
////second click second slot
//// if 2 pos stored, fire drawing (a flag?)
try some code and come back with questions if you need more :)
I've got this very old online example which waits for 2 mouse clicks in order to draw a line():
It's very easy to adapt it to draw a rect() instead. Just follow @_vk's advice! ;)
instead of a flag @GoToLoop used a smart event driven solution... Meaning that the sketch only runs when someone clicks...