Acceleration Color
Use deviceMoved() to detect when the device is rotated. The background RGB color values are mapped to accelerationX, accelerationY, and accelerationZ values.
Open this page on a mobile device to display the sketch.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let r, g, b;
function setup() {
createCanvas(displayWidth, displayHeight);
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);
}