mouseY
GlobalThe y mouse coordinate.
createWindow(200, 200);
stroke(255);
function draw()
background('purple');
line(0, mouseY, width, mouseY);
end
Output
mouseX
GlobalThe x mouse coordinate.
createWindow(200, 200);
stroke(255);
function draw()
background('purple');
line(mouseX, 0, mouseX, height);
end
Output
mouseIsPressed
GlobalIs true
when the mouse is pressed, is false
when it's not.
mousePressed(button);
EventCalled when a mouse button is pressed.
Arguments
button
The pressed mouse button
In the following example, the circle's size increases when the user clicks the mouse.
size = 12;
function setup()
createWindow(400, 400);
textAlign(CENTER);
end
function draw()
background('purple');
text('Click to grow the circle', width/2, 50);
circle(width/2, height/2, size);
end
-- Increase circle size when mouse pressed
function mousePressed()
size = size + 3;
end
Output
mouseReleased(button);
EventCalled when a mouse button is released.
Arguments
button
The released mouse button
In the following example, the circle's size increases when the user clicks the mouse.
size = 12;
function setup()
createWindow(400, 400);
textAlign(CENTER);
end
function draw()
background('purple');
text('Click to grow the circle', width/2, 50);
circle(width/2, height/2, size);
end
-- Increase circle size when mouse released
function mouseReleased()
size = size + 3;
end
Output
mouseWheel(button);
EventCalled when a mouse wheel is used.
Arguments
button
The pressed mouse button
In the following example, the circle's size changes when the user scrolls.
size = 32;
function setup()
createWindow(400, 400);
textAlign(CENTER);
end
function draw()
background('purple');
text('Scroll to change the size', width/2, 50);
circle(width/2, height/2, size);
end
-- Increase circle size when mouse scrolled
function mouseWheel(delta)
size = max(size - delta * 3, 3);
end
Output