Build a Sound-Wave Explorer with Live Oscilloscope in a Single HTML File
You get a one-file interactive sound lab where students hear and see sine, square, triangle and sawtooth waves while changing frequency and amplitude.
The prompt
Act as a front-end developer and physics teacher who builds clear classroom tools. Build Wave Lab, a sound-wave explorer that lets students hear and see sine, square, triangle and sawtooth waves. A large oscilloscope canvas draws the selected wave on a labeled grid (2 ms per division), with dashed lines marking peak amplitude and live readouts for frequency in Hz, nearest note name, period in ms, wavelength in air (343 m/s) and amplitude in percent. Rules: 1) Controls: a Play/Stop button, four waveform toggle buttons, a logarithmic frequency slider from 55 to 1760 Hz, an amplitude slider, and presets for 110 Hz, middle C, A 440 and 880 Hz; shortcuts P or Space to play, 1-4 to pick a shape, M to mute. 2) Sound: use a Web Audio oscillator and gain node, create the AudioContext on the first click or key press, keep volume low, balance square and sawtooth loudness, smooth every change to avoid clicks, and show a visible mute toggle. 3) Below the scope, four clickable mini scopes compare all shapes with one-line notes on their harmonics. 4) Dark navy palette, one green trace color, one amber accent, readable contrast, responsive from 360 to 1280 px with a crisp high-DPI canvas. 5) The trace scrolls slowly only while playing and stays still under prefers-reduced-motion. No external files, libraries or storage. Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.Example output
Tips and common edits
Why this works
- The wave is drawn from math, not an analyser, so the scope looks right on first load even before sound is allowed or when muted.
- Fixed 2 ms grid divisions make frequency visible: double the pitch and exactly twice as many cycles appear.
- Loudness balancing and smoothed gain changes keep square and sawtooth waves comfortable and click-free in a classroom.
Paste the prompt into ChatGPT, Claude or Gemini. Save the returned code as wave-lab.html and open it in any browser, or run it in the chat's preview or canvas. Use headphones at low volume in class.
Common edits
- Add a second oscillator and a 'beats' mode that plays two close frequencies to show interference.
- Change the range to 20-20,000 Hz with a hearing-test mode, or swap the palette to a light theme for projectors.
Keep exploring
More like this
Build a Theremin-Style Pointer Instrument with Live Waveform in One HTML File
A ready-to-paste prompt that builds a canvas theremin. Horizontal motion sets pitch, vertical motion sets volume, notes can snap to a scale, and a live oscilloscope trace shows the sound.
Build a 16-Step Drum Sequencer with Tempo and Swing in One HTML File
A ready-to-paste prompt that makes an AI build a clickable 16-step drum machine with synthesized drums, preset grooves, tempo, swing and a moving playhead.
Build a Classroom Game Show Buzzer Board with Timer Sounds in HTML
A prompt that builds a single HTML quiz-night console with four colored team buzzers, correct and wrong sounds, scoring, and a ticking countdown that ends in a horn.
Build a Generative Ambient Chime Toy With Pentatonic Notes in One HTML File
A ready-to-paste prompt that builds a calm ambient music toy where every tap drops a glowing, drifting ripple and a pentatonic chime, with an auto-play mode.
Build a Guided Breathing Exercise App with Soft Rising Tones in One HTML File
A prompt that produces a single-file breathing guide with box, 4-7-8 and coherent patterns, an expanding circle and gentle synthesized sine swells.
Build a Piano Interval Ear-Training Quiz with Streak Scoring in One HTML File
A one-file interval ear trainer that plays two synthesized piano notes, gives four multiple-choice answers, tracks streaks and shows the answer on a keyboard.