Last active
June 11, 2018 12:28
-
-
Save razdvapoka/38a4b5df537de1b33a3024da72c7d8aa to your computer and use it in GitHub Desktop.
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
// copy and execute in devtools console | |
// to stop execute stop() | |
// to launch again execute go() | |
let handler; | |
const getRandomSign = () => Math.random() > 0.5 ? 1 : -1; | |
const roundRandomNumber = (max, min = 0) => min + Math.floor(Math.random() * max); | |
const fuckShitUp = | |
(maxDeg, isAlternating, maxScale, isRescaling, changeBg) => document | |
.querySelectorAll('*') | |
.forEach(el => { | |
const deg = Math.floor(Math.random() * maxDeg); | |
const sign = isAlternating ? getRandomSign() : 1; | |
const xScale = 1 + getRandomSign() * Math.random() * maxScale; | |
const yScale = 1 + getRandomSign() * Math.random() * maxScale; | |
el.style.transition = 'all 0.2s ease'; | |
// const rotatingTransform = 'rotate(' + sign*deg + 'deg)'; | |
const rotatingTransform = 'rotate3d(' + Math.random() + ',' + Math.random() + ',' + Math.random() + ',' + sign*deg + 'deg)'; | |
const rescalingTransform = isRescaling ? (' scale(' + xScale + ', '+ yScale + ')') : ''; | |
el.style.transform = rotatingTransform + rescalingTransform; | |
if (changeBg) { | |
const red = roundRandomNumber(255); | |
const green = roundRandomNumber(255); | |
const blue = roundRandomNumber(255); | |
const rndColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; | |
el.style.backgroundColor = rndColor; | |
} | |
}); | |
const go = (t = 1000, maxDeg = 5, isAlternating = true, maxScale = 0.1, isRescaling = true, changeBg = true) => { | |
fuckShitUp(maxDeg, isAlternating, maxScale, isRescaling, changeBg); | |
handler = setTimeout(() => go(t, maxDeg, isAlternating, maxScale, isRescaling, changeBg), t); | |
}; | |
const stop = () => clearTimeout(handler); | |
go(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment