Created
December 11, 2019 08:27
-
-
Save datafatmunger/ea9e06b8fdcfa87e99bb34514b041c50 to your computer and use it in GitHub Desktop.
browser-hacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 0 | |
setInterval(() => document.querySelector('h1').style.transform = `rotateY(${i++}deg)`) | |
r = 0 | |
i = setInterval(() => Array.from(document.querySelectorAll("._1zGQT")).forEach(n => n.style.transform = `rotate(${r++}deg)`), 100) | |
i = 0 | |
setInterval(() => document.querySelector('h1').style.transform = `rotateY(${i++}deg)`) | |
ac = new AudioContext() | |
o1 = ac.createOscillator() | |
o1.type = 'square' | |
o1.frequency.value = 100 | |
o1.connect(ac.destination) | |
o1.start() | |
ac = new AudioContext() | |
let lfo = () => { | |
let osc = ac.createOscillator() | |
osc.type = 'sine' | |
osc.frequency.value = 30 | |
let amp = ac.createGain() | |
amp.gain.setValueAtTime(1, ac.currentTime) | |
let lfo = ac.createOscillator() | |
lfo.type = 'triangle' | |
lfo.frequency.value = 0.5 | |
lfo.connect(amp.gain) | |
osc.connect(amp).connect(ac.destination) | |
lfo.start() | |
osc.start() | |
} | |
// 20 | |
let note = (f) => { | |
o1 = ac.createOscillator() | |
o1.type = 'sine' | |
o1.frequency.value = f | |
g = ac.createGain() | |
g.gain.setValueAtTime(0, 0) | |
g.gain.linearRampToValueAtTime(0.25, ac.currentTime + 0.2) | |
g.gain.linearRampToValueAtTime(0, ac.currentTime + 0.5) | |
o1.connect(g).connect(ac.destination) | |
o1.start() | |
} | |
noiseDuration = 1 // 2 | |
bandHz = 400 // max="1200 | |
playNoise = (noiseDuration, bandHz) => { | |
const bufferSize = ac.sampleRate * noiseDuration | |
const buffer = ac.createBuffer(1, bufferSize, ac.sampleRate) | |
let data = buffer.getChannelData(0) | |
for (let i = 0; i < bufferSize; i++) { | |
data[i] = Math.random() * 2 - 1 | |
} | |
let noise = ac.createBufferSource() | |
noise.buffer = buffer | |
let bandpass = ac.createBiquadFilter() | |
bandpass.type = 'bandpass' | |
bandpass.frequency.value = bandHz | |
g = ac.createGain() | |
g.gain.setValueAtTime(1, 0) | |
g.gain.linearRampToValueAtTime(0, ac.currentTime + 0.5) | |
noise.connect(g).connect(bandpass).connect(ac.destination) | |
noise.start() | |
} | |
// 20 | |
play = () => { | |
o1 = ac.createOscillator() | |
o1.type = 'sine' | |
o1.frequency.value = 100 | |
g = ac.createGain() | |
g.gain.setValueAtTime(0, 0) | |
for(let i = 0; i < 60; i++) { | |
o1.frequency.setValueAtTime(Math.random() * 440 + 100, ac.currentTime + i) | |
g.gain.linearRampToValueAtTime(0.25, ac.currentTime + 0.2 + i) | |
g.gain.linearRampToValueAtTime(0, ac.currentTime + 0.5 + i) | |
} | |
o1.connect(g).connect(ac.destination) | |
o1.start() | |
} | |
beat = (f) => { | |
o1 = ac.createOscillator() | |
o1.type = 'triangle' | |
o1.frequency.value = f | |
g1 = ac.createGain() | |
for(let i = 0; i < 60; i++) { | |
g1.gain.setValueAtTime(1, ac.currentTime + i) | |
g1.gain.linearRampToValueAtTime(0, ac.currentTime + 0.5 + i) | |
} | |
o1.connect(g1).connect(ac.destination) | |
o1.start() | |
} | |
bass = (f) => { | |
o1 = ac.createOscillator() | |
o1.type = 'triangle' | |
o1.frequency.value = f | |
g1 = ac.createGain() | |
for(let i = 0; i < 60; i++) { | |
g1.gain.setValueAtTime(1, ac.currentTime + i) | |
g1.gain.linearRampToValueAtTime(0, ac.currentTime + 0.5 + i) | |
} | |
o1.connect(g1).connect(ac.destination) | |
o1.start() | |
} | |
snare = (noiseDuration, bandHz) => { | |
const bufferSize = ac.sampleRate * noiseDuration | |
const buffer = ac.createBuffer(1, bufferSize, ac.sampleRate) | |
let data = buffer.getChannelData(0) | |
for (let i = 0; i < bufferSize; i++) { | |
data[i] = Math.random() * 2 - 1 | |
} | |
let noise = ac.createBufferSource() | |
noise.buffer = buffer | |
let bandpass = ac.createBiquadFilter() | |
bandpass.type = 'bandpass' | |
bandpass.frequency.value = bandHz | |
g = ac.createGain() | |
for(let i = 0; i < 60; i++) { | |
g.gain.setValueAtTime(1, ac.currentTime + i + 0.25) | |
g.gain.linearRampToValueAtTime(0, ac.currentTime + 0.75 + i) | |
} | |
noise.connect(g).connect(bandpass).connect(ac.destination) | |
noise.start() | |
} | |
document.addEventListener('keydown', (e) => { | |
e.preventDefault() | |
if(e.keyCode === 87) note(200) | |
else if(e.keyCode === 78) note(300) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment