Drawing rectangles

edited May 2015 in How To...

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).

Answers

  • what do you want? for us to do this for you?

  • (be careful how you answer)

  • _vk_vk
    edited May 2015

    try writing it in english first like:

    //Pseudo
    
    // some global vars to store clicked position
    //a boolean as a flag?
    
    //in setup
    ////usual stuff
    
    
    //in draw
    //// 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 
    
    
    
    //in mousepressed
    ////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():
    http://studio.processingtogether.com/sp/pad/export/ro.9c9DCUznTwot6/latest
    It's very easy to adapt it to draw a rect() instead. Just follow @_vk's advice! ;)

  • _vk_vk
    edited May 2015

    instead of a flag @GoToLoop used a smart event driven solution... Meaning that the sketch only runs when someone clicks...

Sign In or Register to comment.