当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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 thresold 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

相关用法


注:本文由纯净天空筛选整理自_sh_pallavi大神的英文原创作品 p5.js setMoveThreshold() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。