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

pixel-art-gen

v1.1.2

Published

Generate a pixel art

Downloads

40

Readme

pixel-art-gen

Generate a pixel art from a simple pattern string. (based on pixel-sprite-generator)

Demo

ships

ships screenshot

recoil

recoil screenshot

vader

recoil screenshot

How to use

See the sample code.

Include build/index.js script,

  <script src="https://unpkg.com/pixel-art-gen/build/index.js"></script>

or install from npm.

> npm i pixel-art-gen
import * as pag from "pixel-art-gen";

pag.generate function returns a generated pixel art in a Pixel array ([rotated pattern index][x][y]),

// generate a pixel art
// (with the default options {isMirrorY: true, rotationNum: 16, scale: 2})
// each character in the string array of the 1st arg represents a pixel type
// 'x': a body or an edge
// '-': a body or an empty
// 'o': an edge
// '*': a body
player.pixels = pag.generate([" x", "xxxx"]);

use pag.generateImages to get images,

player.images = pag.generateImages([" x", "xxxx"]);

or generateImagesPromise to wait for loading images.

player.images = await pag.generateImagesPromise([" x", "xxxx"]);

Pixel instance consists of rgb colors, an isEmpty boolean value and a style string.

class Pixel {
  r = 0;
  g = 0;
  b = 0;
  isEmpty = true;
  style: string;
}

Use the pag.draw function to draw the generated pixel art,

// draw a generated pixels
function drawPixels(actor) {
  var a = actor.angle;
  if (a < 0) {
    a = Math.PI * 2 - Math.abs(a);
  }
  const ri = Math.round(a / ((Math.PI * 2) / rotationNum)) % rotationNum;
  pag.draw(context, actor.pixels, actor.pos.x, actor.pos.y, ri);
}

or use pag.drawImages to draw images.

pag.drawImage(context, actor.images, actor.pos.x, actor.pos.y, ri);

Options can be specified in the 2nd arg of the pag.generate (or pag.generateImages) function.

// specify the options in the 2nd arg
enemy.pixels = pag.generate([" x", "xx"], { isMirrorX: true });

Options described below are available.

  isMirrorX: false, // mirror the pattern in the x-axis
  isMirrorY: false, // mirror the pattern in the y-axis
  seed: 0, // random seed
  hue: null, // base color (hue changes randomly when hue = null)
  saturation: 0.8,
  value: 1,
  rotationNum: 1, // create rotated patterns
  scale: null, // scaling
  scaleX: null,
  scaleY: null,
  scalePattern: 1, // scale the pattern
  scalePatternX: null,
  scalePatternY: null,
  isRotatingRight: false, // rotate the pattern
  isRotatingLeft: false,
  isReverseX: false, // reverse the pattern
  isReverseY: false,
  isAddingEdgeFirst: false, // add an edge before randomize
  isInnerEdge: false, // add an edge inside
  colorNoise: 0.1, // how often the color changes randomly
  colorLighting: 1, // lighting effect for the color
  edgeDarkness: 0.4, // darkness of the edge pixels
  isShowingEdge: true, // show the edge pixels
  isShowingBody: true, // show the body pixels
  isLimitingColors: false, // limit the using colors
  isUsingLetterForm: false, // using the letter form for the pattern
  letterFormChar: "x", // the pattern letter for the letter form
  letterFormFontFamily: "monospace", // font for the letter form
  letterFormFontSize: 16,
  letterWidthRatio: 0.8, // for adjusting letter spacing
  letterHeightRatio: 0.9

You can set the default options of the library.

// set the default options
pag.setDefaultOptions({
  isMirrorY: true,
  rotationNum,
  scale: 2
});

Set the random seed by the pag.setSeed function to change a generated pixel art.

// set the random seed to change a generated pixel art
pag.setSeed(seed);