Hi, I’m trying to write some code that will allow me to draw straight lines based on when I press (mousePressed) and release or drag the mouse. (Any of you who have used say AutoCad or similar will know the type of functionality I’m trying to achieve but it’s just lines, nothing else!
I thought I had it sussed by using mousePressed as a variable and using it as a switch to assign mouseX and mouseY as the starting point and then use mouseReleased to do the same but it seems mouseReleased can only be used to call a function. Here is what I have come up with:
PS Apologies if I have not ‘commented’ the code out correctly…I’m new to all of this…I highlighted the code and then hit the <> button above?
Any help would be appreciated…I have tried to research a solution on the website but the ‘paint’ program just divides the line up into segments based on frameRate. I also ended up looking at vectors but my brain started to smoke so I thought it best to stop
Thakyou.
float startX;
float startY;
float finX;
float finY;
void setup() {
size(640, 360);
background(#32B0CE);
}
void draw() {
stroke(255);
line(startX,startY, finX, finY);
}
void mousePressed(){
startX= mouseX;
startY= mouseY;
}
void mouseReleased(){
finX=mouseX;
finY=mouseY;
stroke(0);
}