<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
const seconds = 0.5
const fn = t =>
Math.sin(t * 6000)
* Math.sin(t * 3000)
* Math.sin(t * 1000)
* Math.sin(Math.PI * t / seconds)
// Sound generator
const audioCtx = new AudioContext()
const {sampleRate} = audioCtx
const buffer = audioCtx.createBuffer(
1, sampleRate * seconds, sampleRate
)
const data = buffer.getChannelData(0)
for (var i = 0; i < data.length; i++) {
data[i] = fn(i / sampleRate, seconds)
}
const source = audioCtx.createBufferSource()
source.buffer = buffer
// Visualiser
const analyser = audioCtx.createAnalyser()
const w = analyser.fftSize
const canvas = document.createElement('canvas')
canvas.width = w
canvas.height = 255
const ctx = canvas.getContext('2d')
const waveform = new Uint8Array(analyser.fftSize)
const animate = (t) => {
requestAnimationFrame(animate)
analyser.getByteTimeDomainData(waveform)
ctx.clearRect(0,0, w, 255)
ctx.beginPath()
waveform.forEach((v, i) => {
ctx.lineTo(i, v)
})
ctx.stroke()
}
animate()
document.body.appendChild(canvas)
source.connect(analyser)
analyser.connect(audioCtx.destination)
source.start()
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |