Random Color Strings Not-Golfed
const { random, round } = Math
const TICK = 100
const CHUNKS_PER_TICK = 4
const minChunk = 3
const maxChunk = 10
const diffChunk = maxChunk - minChunk
const generateChance = .9 // 90% change of string generation
const spaceChance = .8 // 80% chance of space
const breakChance = .1 // 10% chance of line break
const numbersChance = .9
const randomChunk = () => round(random() * 0xff).toString(36)
.replace(random() < numbersChance ? /[0-9]/g : '', '')
setInterval(() => {
if (random() < generateChance) {
Array(CHUNKS_PER_TICK).fill(0).forEach(() => {
const stringLeng = round(minChunk + random() * diffChunk)
let chunk = ''
Array(stringLeng).fill(0)
.forEach(() => chunk += randomChunk())
const span = document.createElement('span')
const hue = round(random() * 360)
span.style.color = `hsl(${hue}, 30%, 50%)`
document.body.appendChild(span)
span.innerText = chunk
if (random() < spaceChance) {
document.body.appendChild(document.createTextNode(' '))
}
if (random() < breakChance) {
const br = document.createElement('br')
document.body.appendChild(br)
}
})
}
scrollTo(0, document.body.scrollHeight)
}, TICK)
// just a lazy hack since snippet zone quick editor only supports js...
// normally this goes in a separate file... :D
document.body.innerHTML += `
<style>
body, html {
background: black;
font-family: Oswald, sans-serif;
overflow-wrap: break-word;
text-transform: uppercase;
letter-spacing: 1;
}
br {
height: 1em;
display: block;
}
</style>
`
An expansion on a snippet from a few days ago inspired by a friends codepen fork…