Skip to content

Instantly share code, notes, and snippets.

@fanfare
Last active January 14, 2020 21:41
Show Gist options
  • Save fanfare/bb87eb68cd877a8a01c87482b1548d92 to your computer and use it in GitHub Desktop.
Save fanfare/bb87eb68cd877a8a01c87482b1548d92 to your computer and use it in GitHub Desktop.
javascript:function box() { var synth = new Tone.Synth().toMaster(); var people = document.querySelectorAll("#people p"); function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }; function randhex() { return "#000000".replace(/0/g,function(){ return (~~(Math.random()*16)).toString(16); }); }; (async function(){ for (let i=0;i<people.length;i++) { let color = randhex(); let person = people[i]; let text = person.innerText; person.style.color = color; person.style.textShadow = `0px 0px 10px ${color}`; synth.triggerAttackRelease((text.length * 10), '8n'); await sleep(100); person.style.color = "black"; person.style.textShadow = "none"; }; })(); }; if (typeof Tone === "undefined") { var script = document.createElement('script'); script.onload = function() { box(); }; script.src = "https://cdnjs.cloudflare.com/ajax/libs/tone/14.4.84/Tone.js"; document.getElementsByTagName('head')[0].appendChild(script); } else { box(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment