The doubleClicked() function is invoked whenever a mouse or pointing device causes a dblclick event. This happens when the pointing device is clicked twice in quick succession on a single element. The MouseEvent callback argument could be used to access the details of the click.
Syntax:
doubleClicked([event])
Parameters: This function accepts a single parameter as mentioned above and described below:
- event: This is an optional MouseEvent callback argument. It can be used to access the click details.
The program below illustrate the doubleClicked() function in p5.js:
Example 1: Using double click to change the fill color.
let colorVal = 0; function setup() { createCanvas(500, 300); textSize(24); } function draw() { clear(); // apply fill based on the red component fill(colorVal, 128, 255 - colorVal) text("Double click to change the color", 20, 20); circle(150, 150, 200); } function doubleClicked() { // change the value if // the event occurs if (colorVal < 255) colorVal += 50; else colorVal = 0; } |
Output:

Example 2: Accessing the details of the MouseEvent object.
let y = 60; function setup() { createCanvas(500, 200); textSize(16); text("Double click the mouse to see doubleClicked() function fire", 10, 20); } function doubleClicked(event) { // get the x and y location // of the double click locationX = event.x; locationY = event.y; locString = "Mouse was double clicked at location: " + locationX + ", " + locationY; text(locString, 10, y); y = y + 20; console.log(event); } |
Output:

Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5/doubleClicked
Recommended Posts:
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- D3.js easePolyOut Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
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.


