Created
November 23, 2015 14:35
-
-
Save heyLu/248e4ea8a287e54854d2 to your computer and use it in GitHub Desktop.
Visualize the output of Math.random()
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
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