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
// Run this example on a mobile device // You will need to move the device incrementally further Â
let value = 0; let threshold = 0.5; function setup() { Â
// The function in which we pass the threshold value as default. Â Â setMoveThreshold(threshold); } function draw() { Â Â fill(value); Â ellipse(56, 46, 55, 55); } function deviceMoved() { Â Â value = value + 7; Â Â Â Â Â // increment in the threshold. Â Â threshold = threshold + 0.1; Â Â if (value > 255) { Â Â Â Â value = 0; Â Â Â Â threshold = 30; Â Â } Â Â //Again set the threshold function. Â Â setMoveThreshold(threshold); } |
Output:
Reference: https://p5js.org/reference/#/p5/setMoveThreshold