Don't Spill The Coffee

SENSOR STATUS: WAITING

0

Balance Challenge

Turn your phone into a cup of coffee.
Walk freely without spilling the liquid.
Requires Gyroscope (Mobile)

X-Tilt: 0
Y-Tilt: 0

The Physics of Micro-Electro-Mechanical Systems (MEMS) in Modern Browsers

Your smartphone is more than just a communication device; it is a pocket-sized physics laboratory equipped with sophisticated sensors. This interactive simulation utilizes the device's accelerometer and gyroscope—tiny chips known as MEMS—to detect gravity and rotation. By mapping these physical forces to a virtual liquid simulation, we create a direct link between your physical body mechanics and the digital canvas.

How This Simulation Works

The browser listens for the DeviceOrientationEvent. When you tilt your phone, the beta (front-to-back tilt) and gamma (left-to-right tilt) values change. We apply fluid physics logic—specifically a spring-mass dampening system—to these values to make the "coffee" feel heavy, viscous, and reactive to inertia rather than instantaneous movement.

Chapter 1: The Gyroscope vs. Accelerometer

To successfully "carry the coffee," it is crucial to understand the tools at your disposal. Modern smartphones typically use a sensor fusion approach, combining data from multiple hardware components to determine orientation.

In web development, the DeviceOrientation API abstracts this complexity, providing us with clean Euler angles (Alpha, Beta, Gamma) that represent the device's physical attitude in 3D space.

Chapter 2: The Challenge of Latency and Sensory Conflict

Balance games like "Don't Spill The Coffee" are difficult not just because of physics, but because of human biology. When playing, users often experience a phenomenon known as Sensory Conflict.

Your eyes perceive the liquid moving on a 2D plane (the screen), but your inner ear (vestibular system) feels your body moving in 3D space. If there is significant latency—even a delay of 50 milliseconds—between your hand movement and the visual update, your brain struggles to compensate, leading to over-correction. This is why the "coffee" often sloshes violently when you try to hold it perfectly still; you are reacting to old visual data.

Why Walk?

Walking introduces a complex noise pattern to the sensor data. The vertical oscillation of your gait (bobbing up and down) and the rhythmic impact of your feet hitting the ground create micro-accelerations. A high-quality MEMS sensor detects these. To achieve a high score, you must decouple your arm's stability from your body's motion—a technique often used by steady-cam operators and waiters.

Axis Technical Term Real World Motion
Beta (β) Pitch Tilting the phone forward or backward (Tip to user).
Gamma (γ) Roll Tilting the phone left or right (Side to side).
Alpha (α) Yaw Spinning around like a compass (Not used for balance).

Chapter 3: Privacy & iOS Permissions

Historically, websites could access motion sensors silently. However, researchers discovered that sensor data acts like a "fingerprint"—the unique way you hold your phone and your microscopic hand tremors can identify you.

Starting with iOS 13, Apple introduced a privacy mandate requiring Explicit User Permission. This is why you must click the "Fill Cup" button to play. The browser cannot request sensor access automatically; it must be triggered by a user gesture (like a click or tap). This ensures that you are aware the website is monitoring your physical movement.

Google Chrome and Android generally allow access more freely on secure contexts (HTTPS), though the W3C Generic Sensor API is moving toward a similar permission-based model for the future of the web.

Strategies for High Scores

  1. The "Waiter's Hold": Keep your elbow loose and away from your ribs. This allows your arm to act as a shock absorber, dampening the impact of your footsteps before they reach the phone.
  2. Look Ahead: Don't stare exclusively at the coffee. Use your peripheral vision to navigate the room. Focusing too intently on the liquid causes "Pilot Induced Oscillation," where your corrections create more instability.
  3. Calibration: Ensure you start the game with the phone perfectly flat. The game sets the "zero point" the moment the physics engine initializes.

Ready to test your sensors?

Challenge a friend to walk 10 steps without spilling. Compare stability scores.


Frequently Asked Questions

Why doesn't the liquid move on my computer?

Desktop computers (usually) do not have accelerometers or gyroscopes. This game uses a "mouse fallback" for testing on PCs, where the mouse position simulates tilt, but for the true experience, you must use a smartphone or tablet.

Is my data being recorded?

No. The sensor data is processed locally within your browser's JavaScript engine (Client-Side) to render the liquid. No motion data is sent to any server.

Recommended Privacy & Data Tools