deviceMoved() を使用して、デバイスがいつ回転したかを検出します。背景のRGBカラー値は、accelerationX、accelerationY、accelerationZの値にマッピングされます。
deviceMoved acceleration color
Mobile Sensors
View Source Code
/*
* @name Acceleration Color
* @description Use deviceMoved() to detect when the device is rotated. The background RGB color values are mapped to accelerationX, accelerationY, and accelerationZ values.
*/
let r, g, b;
function setup() {
// createCanvas(displayWidth, displayHeight);
createCanvas(windowWidth, windowHeight);
r = random(50, 255);
g = random(0, 200);
b = random(50, 255);
}
function draw() {
background(r, g, b);
console.log('draw');
}
function deviceMoved() {
r = map(accelerationX, -90, 90, 100, 175);
g = map(accelerationY, -90, 90, 100, 200);
b = map(accelerationZ, -90, 90, 100, 200);
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.