Skip to content

Instantly share code, notes, and snippets.

@krmgns
Created April 5, 2021 23:13
Show Gist options
  • Save krmgns/9b31f64ea0411d05757bfff241d92df2 to your computer and use it in GitHub Desktop.
Save krmgns/9b31f64ea0411d05757bfff241d92df2 to your computer and use it in GitHub Desktop.
<canvas id="c" width="1024" height="1024">
<script>
// Creds: https://twitter.com/aemkei/status/1378106731386040322
// let cx = c.getContext('2d'), x, y
// for (x = 0; x < 256; x++) {
// for (y = 0; y < 256; y++) {
// if ((x ^ y) % 2) {
// cx.fillRect(x * x, y * y, x, y);
// }
// }
// }
let cx = c.getContext('2d'), r = Math.random, x, y, z
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
if ((x ^ y) % 2) {
// z = r() * 10 | 0;
// z = r() * (x ^ y) | 0;
z = r() * [x, y][r() * 2 | 0] | 0
cx.fillRect(x * z, y * z, z, z)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment