Skip to content

Instantly share code, notes, and snippets.

@ivarvong
Created January 10, 2020 22:09
Show Gist options
  • Save ivarvong/2184c3573c7a27b21abfcde16d64741e to your computer and use it in GitHub Desktop.
Save ivarvong/2184c3573c7a27b21abfcde16d64741e to your computer and use it in GitHub Desktop.
<!doctype html>
<body>
<h1 style="font-size: 100px;"></h1>
<script src="https://d3js.org/d3-color.v1.min.js"></script>
<script>
const $h1 = document.querySelector('h1')
function random(l) {
const a = parseInt((Math.random() - 0.5) * 256)
const b = parseInt((Math.random() - 0.5) * 256)
return d3.lab(l, a, b)
}
function set() {
const l = parseInt(Math.random() * 100)
const color1 = random(l).formatRgb()
const color2 = random(l).formatRgb()
$h1.innerText = `${color1}\n${color2}`
document.body.style.color = color1
document.body.style.backgroundColor = color2
}
set()
// setInterval(set, 250)
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment