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

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

One HTML file. Save it and open it in any browser.Open full screen

Example: Wave Lab, a sound-wave explorer for physics lessons.

Press Play tone (or P / Space) to hear a 220 Hz sine wave and watch it scroll on the oscilloscope. Drag the frequency slider and count how many cycles fit in the grid; drag amplitude to see the dashed peak lines move. Switch shapes with the buttons or keys 1-4, or click a mini scope to compare timbres at the same pitch. M mutes. Readouts show period, note and wavelength.

Written by AI from this prompt. Your results will vary.

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.

Prompt details

By
Prompts-GPT editors
Published

Did this prompt work?

Keep exploring

More in Sound Effects & Music