Viewing a saved revision (read-only)
8VcT4mV-TVqjqFPJK7bOR
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 orange spheres bouncing around inside an invisible bounding box. The balls have varied sizes and independent physics, including gravity, wall bounces, and sphere-sphere collisions. Collisions drive procedurally synthesized sound effects generated in real time with the Web Audio API (oscillators + noise buffers, no audio files).
Structure
index.html- HTML entry point with import map for Three.jsmain.js- Animation loop and setup orchestrationconfig.js- Tunable constants (sphere sizes, spacing, physics, bounds, audio)scene.js- Scene creation and lightingsphereCube.js- Creates the spheres and their physics statesimulation.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 dynamic collision sound effects
Physics
Each sphere has its own radius, position, and velocity. 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.
Sound
Sound effects are generated on the fly using software synthesis (audio.js) rather than loading audio files:
- Wall bounces trigger a short percussive blip: a sine oscillator with a fast pitch drop, scaled by the impact speed.
- Sphere-sphere collisions trigger a richer "clack": a noise burst (generated via a
ScriptProcessor-freeAudioBufferof white noise) plus a resonant oscillator, with pitch derived from the combined sphere size. - 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" overlay appears first. Click it (or press any key) to unlock the audio context.
Controls
- Drag to orbit the view and scroll to zoom.
- Click Enable Sound to start the audio engine (required by browser autoplay policies).
- 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 6kC_RpYeyPkvdRgxURGBG — inspiration for synthesizing sound with the Web Audio API (oscillators, filters, envelopes).
- Visualization 1676011d21df47619390edc7384163c3 — reference for triggering sounds from user/interaction events via the audio context.