Socket
Socket
Sign inDemoInstall

@noise-machines/pixel-matrix

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @noise-machines/pixel-matrix

A tiny (< 2 KB) library for playing with pixels.


Version published
Weekly downloads
7
Maintainers
1
Install size
13.5 kB
Created
Weekly downloads
 

Readme

Source

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')

// Returns a random number between 0 and 256.
const getRandomColorChannel = () => Math.floor(Math.random() * 256)

// Colors in Pixel Matrix are just JSON objects.
const getRandomColor = () => {
  return {
    red:  getRandomColorChannel(),
    green: getRandomColorChannel(),
    blue: getRandomColorChannel(),
    alpha: 255
  }
}

// Create a pixel matrix that's the same width and height as the canvas,
// then populate it with random colors.
const pixelMatrix = new PixelMatrix(canvas.width, canvas.height).map(getRandomColor)

// Draw to the canvas.
pixelMatrix.putPixels(canvas)

FAQs

Last updated on 27 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc