Pixel Matrix
A tiny (< 2 KB) library for playing with pixels.
Live Demo
Install
yarn add @noise-machines/pixel-matrix
Usage
Create a random image
import PixelMatrix from '@noise-machines/pixel-matrix'
const canvas = document.querySelector('canvas')
const getRandomColorChannel = () => Math.floor(Math.random() * 256)
const getRandomColor = () => {
return {
red: getRandomColorChannel(),
green: getRandomColorChannel(),
blue: getRandomColorChannel(),
alpha: 255
}
}
const pixelMatrix = new PixelMatrix(canvas.width, canvas.height).map(getRandomColor)
pixelMatrix.putPixels(canvas)