The deviceMoved() function runs when the mobile device displaying the sketch moves. In this example, the accelerationX, accelerationY, and accelerationZ values set the position and size of a circle. This only works for mobile devices.
Mobile Device Movement: Revised by Kasey Lichtlyter. Edited and maintained by p5.js Contributors and Processing Foundation. Licensed under CC BY-NC-SA 4.0.
You can find the code history of these examples here: 2023 code, pre-2023 code. You can suggest improvements by contributing to the current website!
Related Examples

A squiggly rainbow line on a black background.
Drawing Lines
Draw with the mouse.

A small green circle on a black background.
Animation with Events
Pause and resume animation.

White circles on a black background, with varying degrees of transparency.
Mobile Device Movement
Animate based on device motion.

A small black circle on a rainbow, lattice-shaped path, on top of a grey and white striped background.
Conditions
Use if and else statements to make decisions while your sketch runs.