Drawing lines with user defined coordinates
in
Programming Questions
•
5 months ago
Hi guys. So i´ve just started playing around with processing and i am trying to write a program that lets the user click at two random points on the screen and then a line should appear between these two points.
i´ve written the following code, but i wont work and i just cant figure out why :S .. Can anyone explain it to me?
Thanks in advance.
- void setup(){
- size(400,400);
- smooth();
- }
- void draw(){
- int pointOneX;
- int pointOneY;
- int pointTwoX;
- int pointTwoY;
- boolean pointStored = false;
- if(mousePressed){
- if(pointStored == true){ //if coordinates for the starting point of the line has been recorded, the line is drawn and the boolean pointStored is set to false so that the next line can be drawn.
- pointTwoX = mouseX;
- pointTwoY = mouseY;
- line(pointOneX,pointOneY,pointTwoX,pointTwoY);
- pointStored = false;
- }else{ // coordinates for the starting point of the line is recorded
- pointOneX = mouseX;
- pointOneY = mouseY;
- pointStored = true;
- }
- }
- }
1