Last active
June 12, 2023 15:44
-
-
Save iamnottheway/90f965201a9bfa34fc0d52ec26aa084c to your computer and use it in GitHub Desktop.
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
function fastNoise(canvas) { | |
canvas.width = 300; | |
canvas.height = 300; | |
const totalPixels = canvas.width * canvas.height * 4; | |
const ctx = canvas.getContext("2d"); | |
const arr = new Uint8ClampedArray(totalPixels); | |
for (let i = 0; i < arr.length; i += 4) { | |
let r1 = (Math.random()>=0.5) ? 255 : 0; | |
arr[i + 0] = r1; | |
arr[i + 1] = r1; | |
arr[i + 2] = r1; | |
arr[i + 3] = r1 === 255 ? 0 : 100; | |
} | |
let imgd = new ImageData(arr, canvas.width, canvas.height); | |
ctx.putImageData(imgd, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment