p5.js setMoveThreshold()函数
函数setMoveThreshold()用于设置 deviceMoved()函数的移动阈值。默认阈值设置为0.5 。
句法:
setMoveThreshold(value)
参数:此函数接受一个如上所述和如下所述的参数。
- value:它是一个表示阈值的数字。
例子:
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);
}
输出:
参考: https://p5js.org/reference/#/p5/setMoveThreshold