p5.js | Mouse | mouseReleased()

The mouseReleased() function in p5.js works when mouse button released. The touchEnded() function is used instead of mouseReleased() function when mouseReleased() function is not defined.

Syntax:

mouseReleased(Event)

Below programs illustrate the mouseReleased() function in p5.js:



Example 1: This example uses mouseReleased() function to change the background color.

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
      
    // Create Canvas
    createCanvas(500, 500);
}
   
let value = 0;
  
function draw() {
      
    // Set the background color
    background(200);
      
    // Fill the color
    fill(value, value-50, value-100);
      
    // Create rectangle
    rect(25, 25, 460, 440);
      
    // Set the filled color
    fill('lightgreen');
      
    // Set the font size
    textSize(15);
      
    // Display result
    text('Keep on Clicking the Mouse Across'
        + ' the page \nto change Canvas Color.',
        windowHeight/10, windowWidth/4);
}
  
function mouseReleased() {
    value = value + 5;
      
    if (value > 255) {
        value = 0;
    }
}

chevron_right


Output:

Example 2: This example uses mouseReleased() function to change the mouse pointer color.

filter_none

edit
close

play_arrow

link
brightness_4
code

let valueX;
let valueY;
  
function setup() {
      
    // Create Canvas
    createCanvas(500, 500);
}
   
function draw() {
      
    // Set background color
    background(200); 
      
    // Fill the color
    fill('green');
      
    // Set font size
    textSize(25);
      
    text('Drag mouse to change color', 30, 30);
      
    // Fill color according to mouseMoved() 
    fill(valueX, 255-valueY, 255-valueX);
      
    // Draw ellipse  
    ellipse(mouseX, mouseY, 115, 115);
}
  
function mouseReleased() {
    valueX = mouseX%255;
    valueY = mouseY%255;
}

chevron_right


Output:

Reference: https://p5js.org/reference/#/p5/mouseReleased



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.