Viewing a saved revision (read-only)
Ewe-bruJ8MkvJoNqSc7fB
This interactive WebGL visualization displays a 4×4×4 cube of spheres with warm orange color variations. Each sphere uses Three.js MeshPhongMaterial with randomly varied HSL saturation and lightness values, creating a subtle gradient effect. The entire cube group rotates continuously in both the x and y axes through the animation loop, while OrbitControls allows users to zoom and pan around the structure. The scene uses 64 individually positioned spheres, rendered with directional and ambient lighting for depth.
Bouncing Balls Cube
A Three.js visualization of colored spheres bouncing around inside an invisible bounding box. The balls have varied sizes and independent physics, including gravity, wall bounces, and sphere-sphere collisions.
The balls stay frozen in their initial grid until the user clicks Enable Sound & Drop Balls (or presses any key). This satisfies the browser autoplay policy and makes the first frame a calm, still grid.
Structure
index.html- HTML entry point with import map for Three.jsmain.js- Animation loop, UI wiring, and reset handlingconfig.js- Tunable constants (sphere sizes, spacing, physics, bounds, audio)scene.js- Scene creation and lightingsphereCube.js- Creates the spheres and their physics state, plus resetsimulation.js- Per-frame physics update (gravity, walls, collisions) and collision event reportingrenderer.js- WebGL renderer setupcamera.js- Perspective camera setupcontrols.js- OrbitControls setupaudio.js- Web Audio API software synthesizer for plucked-string collision sounds
Physics
Each sphere has its own radius, position, and velocity. Once started, every frame:
- Gravity is applied to the vertical velocity.
- Velocity is dampened and capped.
- Position is advanced by velocity.
- Wall collisions reflect velocity while respecting each sphere's radius.
- Sphere-sphere collisions use the combined radii to detect contact and separate balls.
Colors
Each ball is assigned a distinct hue spanning the full color wheel based on its index in the grid, so the cube reads as a rainbow of colors rather than a single orange family.
Sound
Sound effects are generated on the fly using software synthesis (audio.js) rather than loading audio files.
- Every ball has a fixed pitch. Balls are assigned unique notes spread chromatically from a base of A3 (220 Hz) across
config.audio.pitchStepssemitone steps. - Wall bounces play a plucked-string note at that ball's own pitch.
- Sphere-sphere collisions play a plucked-string note at the average of the two balls' pitches.
- A plucked-string tone is built from a bright, decaying low-pass filter on a sawtooth (plus an octave harmonic) with a near-instant attack followed by an exponential ring-out. A short band-passed noise burst acts as the "pick" transient.
- Impact volume is proportional to the collision's relative speed, so gentle taps are quiet and hard hits are loud.
- A master gain node, a gentle low-pass filter, and a soft limiter keep the mix from clipping.
Because browsers require a user gesture before audio can start, an "Enable Sound & Drop Balls" overlay appears first. Click it (or press any key) to unlock the audio context and release the balls.
Controls
- Drag to orbit the view and scroll to zoom.
- Click Enable Sound & Drop Balls to start the audio engine (required by browser autoplay policies) and begin the physics.
- Tap anywhere on the scene to reset the simulation: every ball snaps back to its starting grid position and its velocity is cleared, so the whole grid drops again from the top.
- Use the Sound checkbox in the top-right corner to mute/unmute.
- Adjust the Volume slider to taste.
- Press
Mto toggle mute at any time.
References
- Visualization 7b12d243be4643399102ac192dfa54f9 — inspiration for synthesizing pitched tones with the Web Audio API and mapping pitch to entities.
- Visualization 23b4f01cbe204d51b77b2de6498ee568 — inspiration for the bouncing-balls physics reset behavior.