The touchEnded() function in p5.js is called when a touch ends. If no touchEnded() function is defined, the mouseReleased() function will be called instead if it is defined.
Syntax:
touchEnded([Event])
Below program illustrates the touchEnded() function in p5.js:
Example-1:
let valueX; let valueY; function setup() { // Create Canvas of size 500*500 createCanvas(500, 500); } function draw() { // set background color background(200); fill('green'); // set text and text size textSize(25); text('Touch to change color', 30, 30); // fill color according to touchEnded() fill(valueX, 255 - valueY, 255 - valueX); // draw ellipse ellipse(mouseX, mouseY, 115, 115); } function touchEnded() { valueX = mouseX % 255; valueY = mouseY % 255; } |
chevron_right
filter_none
Output:

Example-2:
let valueX; let valueY; function setup() { // Create Canvas of size 500*500 createCanvas(500, 500); } function draw() { // set background color background(200); fill('green'); // set text and text size textSize(25); text('Touch and Move to change color', 30, 30); // fill color according to touchEnded() fill(valueX, 255 - valueY, 255 - valueX); // draw rectangle rect(mouseX, mouseY, 115, 115); fill(valueY, 255 - valueX, 255 - valueX); rect(mouseX, mouseY + 115, 115, 115); fill(255 - valueY, 255 - valueX, 255 - valueY); rect(mouseX - 115, mouseY, 115, 115); fill(255 - valueY, 255 - valueY, 255 - valueY); rect(mouseX - 115, mouseY + 115, 115, 115); } function touchEnded() { valueX = mouseX % 255; valueY = mouseY % 255; } |
chevron_right
filter_none
Output:

Reference: https://p5js.org/reference/#/p5/touchEnded
Recommended Posts:
- PHP | touch( ) function
- p5.js Touch | touchStarted()
- p5.js Touch | touchMoved()
- How to detect touch screen device using JavaScript?
- How to use jQuery touch events plugin for mobiles ?
- Tips for Website Building - From Development to Monetization Phase
- Google AMP amp-carousel
- Google AMP amp-autocomplete
- Google AMP amp-bind-recaptcha
- Google AMP amp-brightcove
- Collect.js has() Method
- How to disable download option in amp-audio in Google AMP ?
- How to set an image placeholder for amp-anim in Google AMP ?
- Google AMP amp-facebook-like
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.


