Skip to content

Instantly share code, notes, and snippets.

@chamun
Created October 23, 2020 18:26
Show Gist options
  • Save chamun/3bde1ad407dfc78a4eaf5beb1690a3b3 to your computer and use it in GitHub Desktop.
Save chamun/3bde1ad407dfc78a4eaf5beb1690a3b3 to your computer and use it in GitHub Desktop.
Bongo Cat plays Baby Shark
// https://bongo.cat/
// Copy and paste in the browser console.
const playNote = key => {
const downEvent = new KeyboardEvent('keydown', { 'key': key } )
const upEvent = new KeyboardEvent('keyup', { 'key': key } )
document.dispatchEvent(downEvent);
setTimeout(() => document.dispatchEvent(upEvent), 100);
}
const playSong = (score, tempo) =>
score
.reduce((acc, [note, length]) => {
const time = acc + length * tempo;
if(note !== '!')
setTimeout(() => playNote(note), time)
return time;
}, 400)
const babyShark = [
["3", 1/2],
["5", 1/2],
["8", 1/4],
["8", 1/4],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["3", 1/4],
["5", 1/4],
["8", 1/4],
["8", 1/4],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["3", 1/4],
["5", 1/4],
["8", 1/4],
["8", 1/4],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["8", 1/8],
["8", 1/4],
["8", 1/4],
["8", 1/4],
["7", 1/4],
[" ", 1/4],
["!", 1/2],
]
playSong(
babyShark
.concat(babyShark)
.concat(babyShark)
, 800);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment