p5.js setMoveThreshold() Function
Last Updated :
03 Dec, 2021
The function setMoveThreshold() is used to set the movement threshold for the deviceMoved() function. The default threshold is set to 0.5.
Syntax:
setMoveThreshold(value)
Parameter: This function accepts a single parameter as mentioned above and described below.
- value: It is a number which denotes the threshold value.
Example:
Javascript
let value = 0;
let threshold = 0.5;
function setup() {
setMoveThreshold(threshold);
}
function draw() {
fill(value);
ellipse(56, 46, 55, 55);
}
function deviceMoved() {
value = value + 7;
threshold = threshold + 0.1;
if (value > 255) {
value = 0;
threshold = 30;
}
setMoveThreshold(threshold);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/setMoveThreshold
Share your thoughts in the comments
Please Login to comment...