Last active
October 28, 2018 22:35
-
-
Save zz85/4707ebd0320413c996ff2629a2a4b267 to your computer and use it in GitHub Desktop.
drunk video script
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
/** | |
* 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() |
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
function u() { | |
requestAnimationFrame(u) | |
;[...document.querySelectorAll('video')].map(e => { | |
e.playbackRate = Math.sin(Date.now() * 0.004) * 0.2 + 0.6 | |
}) | |
} | |
u() |
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
// 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