當設備連續旋轉超過 90 度時調用函數 deviceTurned() s。觸發設備 turned() 方法的軸存儲在 turnAxis 變量中。
通過將 turnAxis 變量與“X”、“Y”或“Z”進行比較,可以鎖定此函數以在所有三個 X、Y 或 Z 軸上觸發。
這是移動應用程序開發函數,允許訪問特定傳感器和操作模式,如檢測設備中的運動、加速度、旋轉、航向和位置。
用法:
deviceTurned()
現在我們將在安卓手機上運行一些例子。
- 第1步:手機任意瀏覽器打開p5.js的在線網頁編輯器“https://editor.p5js.org/”
- 第2步:在編輯器部分編寫以下代碼並運行它以查看輸出。
範例1:
Javascript
// Run this example on a mobile device
// Rotate the device by 90 degrees in the
// X-axis or Y-axis or Z- axis to change the value .
let value = 0;
function draw() {
fill(value);
triangle(45, 100, 54, 5, 100, 100);
}
// Set the the device turned function.
function deviceTurned() {
if (turnAxis === 'X' ||turnAxis === 'Y'|| turnAxis === 'Z') {
if (value === 0) {
value = 255;
} else if (value === 255) {
value = 0;
}
}
}
輸出:我們將通過在 X、Y 或 Z 方向旋轉 90 度來轉動我們的設備來實現這一點。
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- Tensorflow.js tf.layers.embedding()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
注:本文由純淨天空篩選整理自_sh_pallavi大神的英文原創作品 p5.js deviceTurned() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。