當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。