Skip to content

Instantly share code, notes, and snippets.

@heyLu
Created November 23, 2015 14:35
Show Gist options
  • Save heyLu/248e4ea8a287e54854d2 to your computer and use it in GitHub Desktop.
Save heyLu/248e4ea8a287e54854d2 to your computer and use it in GitHub Desktop.
Visualize the output of Math.random()
document.head.innerHTML = "<title>Math.random() noise!</title>"; document.body.innerHTML = "<canvas></canvas>"; canvas = document.querySelector("canvas"); canvas.width = canvas.height = 300; ctx = canvas.getContext("2d"); ctx.clearRect(0, 0, canvas.width, canvas.height); for (let x = 0; x < canvas.width; x++) { for (let y = 0; y < canvas.height; y++) { r = Math.floor(Math.random() * 255); ctx.fillStyle = `rgb(${r}, ${r}, ${r})`; ctx.fillRect(x, y, 1, 1); } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment