Skip to content

Instantly share code, notes, and snippets.

@iamnottheway
Last active June 12, 2023 15:44
Show Gist options
  • Save iamnottheway/90f965201a9bfa34fc0d52ec26aa084c to your computer and use it in GitHub Desktop.
Save iamnottheway/90f965201a9bfa34fc0d52ec26aa084c to your computer and use it in GitHub Desktop.
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