mousePressed()
is called once after every time a mouse button is pressed.mouseReleased()
is called every time a mouse button is released.mouseClicked()
is called once after a mouse button has been pressed and then released.mouseMoved()
is called every time the mouse moves and a mouse button is not pressedmouseDragged()
is called once every time the mouse moves and a mouse button is pressed.mouseButton
is the variable that stores which button is pressed. Its values are LEFT, RIGHT, or CENTER depending on which button is pressed.mousePressed
is true if a mouse button is pressed and false if a button is not pressed.mouseX and mouseY
contains the current horizontal/verticle coordinate of the mouse.pmouseX and pmouseY
contains the previous horizontal/verticle coordinate of the mouse- Draw points along the way mouse is dragged.
- Try: Draw line along the way mouse is clicked.
//draw a from(20,20) to mouse point as mouse moves
void draw()
{
background(204);
line(20, 20,mouseX, mouseY);
}
//draw a from(20,20) to a point where mouse is pressed
void draw()
{
background(204);
smooth();
}
void mousePressed() {
if(mouseButton == LEFT){
line(20, 20,mouseX, mouseY);
noLoop();
}
else{
loop();
}
}
boolean dragged = false;
int x =0;
int y =0;
void setup(){
background(255);
smooth();
}
void draw(){
if(dragged){
point(x,y);
}
dragged = false;
}
void mouseDragged(){
dragged = true;
x = mouseX;
y = mouseY;
}