Created
October 26, 2023 12:59
-
-
Save BolajiOlajide/4da12eff0a6388a8c152bf3da33a0fe0 to your computer and use it in GitHub Desktop.
svelte-paint-gradient.js
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
export function paint(context, t) { | |
const { width, height } = context.canvas; | |
const imageData = context.getImageData(0, 0, width, height); | |
for (let p = 0; p < imageData.data.length; p += 4) { | |
const i = p / 4; | |
const x = i % width; | |
const y = (i / width) >>> 0; | |
const red = 64 + (128 * x) / width + 64 * Math.sin(t / 1000); | |
const green = 64 + (128 * y) / height + 64 * Math.cos(t / 1000); | |
const blue = 128; | |
imageData.data[p + 0] = red; | |
imageData.data[p + 1] = green; | |
imageData.data[p + 2] = blue; | |
imageData.data[p + 3] = 255; | |
} | |
context.putImageData(imageData, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment