npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grid-noise

v0.0.1

Published

Add noise to grid and draw it on it. Can be used to style images.

Downloads

1

Readme

grid-noise

Add your effects to your blocks 👾

Get started

Package is framework-agnostic and can be used in plain JavaScript projects.

To install package just write:

$ npm i grid-noise

Using

This package allows you transform part of the image in some mosaic way.

Actually it can transform any block without children.

See an example here.

For this you should call mosaic function with options.

It is simple object with configuration properties:

interface MosaicOptions {
  /** Length of cell. By default, it is **20px**. */
  readonly cell?: number;
  /** Describes figure shift from grid center. */
  readonly shift: Shift;
  /** Defines size of fugure relative to lowest side of a grid. */
  readonly range: number;
  /** Width of grid. */
  readonly width?: number;
  /** Height of grid. */
  readonly height?: number;
  /**
   * Element in DOM from which _width_ and _height_
   * can be taken. If _width_, _height_ and _element_
   * are provided then first two arguments will take
   * precedence while calculating size.
   */
  readonly element?: string | HTMLElement;
  /**
   * Classes that will be added randomly to cells that
   * will be covered by figure.
   */
  readonly effects?: ReadonlyArray<string>;

  /** Function that is used to build figure. */
  figure: FigureCreator<Figure>;
}

You should provide at least four necessary properties: shift, range, figure and element. These properties are necessary to draw transformed block as grid and to know where we should insert transformed block. By default, size of block will be taken from provided element, but you can change it by providing width and height properties.

Package handles <img> element specially: it can take image source and gather the image from cells. Width of created block will be natural width of image and for height is the same behavior.

  • cell property defines dimension of single cell in grid. You can customize it as you need.

  • figure used to build shape of the area of a block that should be transformed.

  • shift parameter describes shift of the center of a circle from grid center. It is object with dx and dy properties that can be any number from -1 to 1.

  • range is abstract dimension of size of the figure. It can be any number from 0 to 1.

import { mosaic } from 'grid-noise';

const img = document.querySelector('img');

mosaic({
  range: 0.4,
  element: img,
  figure: circle,
  shift: { dx: 0.7, dy: 0.5 },
});

At that time there is only one figure available - circle.

After building mosaic on the page you need to import base styles for it.

@import 'grid-noise/styles.css';

You need style processor to import these styles into your project. Like PostCSS. Or if you use JavaScript bundlers, you can import style file directly in .js file:

import 'grid-noise/styles.css';

Word from author

Have fun! ✌️