Skip to content

Instantly share code, notes, and snippets.

@zz85
Last active October 28, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zz85/4707ebd0320413c996ff2629a2a4b267 to your computer and use it in GitHub Desktop.
Save zz85/4707ebd0320413c996ff2629a2a4b267 to your computer and use it in GitHub Desktop.
drunk video script
/**
* seeing how @thespite gets drunk
* https://twitter.com/thespite/status/1056264007450062848
*/
e = t => t < .5 ? 2 * t * t : -1 + (4 - 2 * t ) * t,
n = _ => performance.now(), cT = n(),
nT = cT,
cV = 1,
nV = 1,
r = Math.random;
function u() {
requestAnimationFrame(u)
t = ( n() - cT ) / ( nT - cT )
v = cV + e(t) * (nV - cV)
if (t > 1) {
v = nV
nV = .55 + .25 * r()
cT = n()
nT = cT + 200 + 800 * r()
// console.log(nV, nT - cT)
}
[...document.querySelectorAll('video')].map(e => {e.playbackRate = v})
}
u()
function u() {
requestAnimationFrame(u)
;[...document.querySelectorAll('video')].map(e => {
e.playbackRate = Math.sin(Date.now() * 0.004) * 0.2 + 0.6
})
}
u()
// visualize t values
plot = (() => {
const
canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
w = canvas.width = 800,
h = canvas.height = 400
let
t = 0
document.body.appendChild(canvas)
return function plot(x) {
console.log(x)
ctx.clearRect(t, 0, 1, h)
ctx.fillRect(t, x * h * 0.5 | 0, 1, 1)
t = (t + 1) % w
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment