-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmakenoise.min.js
1 lines (1 loc) · 1.25 KB
/
makenoise.min.js
1
((audioContext,freq,delay,waveform)=>{"use strict";const levels={"#1e6823":freq*(3/2)*4,"#44a340":freq*(3/2)*3,"#8cc665":freq*(3/2)*2,"#d6e685":freq*(3/2),"#eeeeee":freq};const createOscillator=(fillNodeValue)=>{const oscillator=audioContext.createOscillator();const gainNode=audioContext.createGain();gainNode.gain.value=0.1;oscillator.type=waveform;oscillator.frequency.value=levels[fillNodeValue];oscillator.connect(gainNode);gainNode.connect(audioContext.destination);return{start:()=>oscillator.start(0),stop:()=>oscillator.stop()}};const createNotes=(week)=>{return week.map((day)=>{const fillNodeValue=day.attributes.fill.nodeValue;const oscillator=createOscillator(fillNodeValue);return{play:()=>{day.attributes.fill.nodeValue="red";oscillator.start()},stop:()=>{day.attributes.fill.nodeValue=fillNodeValue;oscillator.stop()}}})};const delayPlay=(noteBar)=>{return(iter)=>{setTimeout(()=>{for(let note of noteBar){note.play();setTimeout(()=>{note.stop()},delay/2)}},delay*iter)}};const noteBars=([].slice.call(document.getElementsByTagName("g"))).slice(1).map((week)=>{return createNotes([].slice.call(week.getElementsByClassName("day")))}).map((day)=>{return delayPlay(day)});let i=0;for(let noteBar of noteBars){noteBar(i+=1)}})(new AudioContext,440,110,"sawtooth");