mouse

v0.1.7
mouseYGlobal

The y mouse coordinate.

createWindow(200, 200);
stroke(255);

function draw()
  background('purple');
  
  line(0, mouseY, width, mouseY);
end

Output

See mouseY in mouse.h
mouseXGlobal

The x mouse coordinate.

createWindow(200, 200);
stroke(255);

function draw()
  background('purple');
  
  line(mouseX, 0, mouseX, height);
end

Output

See mouseX in mouse.h
pmouseYGlobal

The y mouse coordinate from the previous draw call.

See pmouseY in mouse.h
pmouseXGlobal

The x mouse coordinate from the previous draw call.

See pmouseX in mouse.h
mouseIsPressedGlobal

Is true when the mouse is pressed, is false when it's not.

See mouseIsPressed in mouse.h
mousePressed(button);Event

Called when a mouse button is pressed.

Arguments

buttonThe 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

See mousePressed in mouse.h
mouseReleased(button);Event

Called when a mouse button is released.

Arguments

buttonThe 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

See mouseReleased in mouse.h
mouseWheel(button);Event

Called when a mouse wheel is used.

Arguments

buttonThe 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

See mouseWheel in mouse.h