An ESP-IDF demo for the Cheap Yellow Display that renders a fish-shaped spring-mass simulation on an ILI9341 TFT using the DGX graphics component.
The scene is built from 23 mass points connected by springs. Most of the springs are hidden structural braces; the visible springs and a few colored nodes form a fish silhouette. The fish nose is tethered to a moving anchor point, which keeps the whole shape in motion without any user input.
- Initializes the CYD display over SPI.
- Creates a virtual framebuffer the same size as the physical panel.
- Builds a fish-like truss of balls and coils.
- Simulates spring forces, damping, boundary bounces, and a moving anchor point.
- Draws the result to the virtual screen and copies it to the TFT at about 60 FPS.
Each coil behaves like a damped spring between two balls.
Along the spring axis, the force is based on Hooke's law plus velocity damping:
F = k * (length - rest_length) + c * (relative_velocity dot axis)
Where:
kis the spring stiffness.rest_lengthis the spring length when the scene is constructed.cis the damping coefficient.axisis the unit vector from one ball to the other.
The simulation uses semi-implicit Euler integration:
- Accumulate forces from connected springs.
- Convert force to acceleration with
a = F / m. - Update velocity with
v += a * dt. - Update position with
x += v * dt.
To keep the motion stable, the code also clamps speed, rejects non-finite positions, and bounces balls off the screen edges. A global drag constant exists in the source, but the actual drag step is currently commented out; the visible damping comes from the springs and the boundary logic.
The demo is configured for the CYD-style ILI9341 SPI panel with these pins:
- MOSI: GPIO 13
- MISO: GPIO 12
- SCLK: GPIO 14
- CS: GPIO 15
- DC: GPIO 2
- Backlight: GPIO 21
- Reset: not connected
Use standard ESP-IDF commands from the project root:
idf.py set-target esp32
idf.py menuconfig
idf.py build
idf.py flash monitorIf you are using a different ESP32 target or a different CYD variant, adjust the target and pin mapping in main/main.c.
- main/main.c - app entry point, physics, scene setup, and rendering.
- main/CMakeLists.txt - component registration.
- CMakeLists.txt - ESP-IDF project definition.
- The rendered fish is not interactive in the current version.
- The nose is the only actively targeted ball; the anchor point is relocated when the nose gets too close.
- Rendering uses DGX's virtual screen and ILI9341 driver rather than drawing directly to the panel.
