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

spaceship-sprites

v1.1.0

Published

Spaceship Sprite is a random ship sprite generator in typescript.

Downloads

35

Readme

Spaceship Sprites

Contents

Usage

Building a single sprite

import { Color, Sprite, SpriteBuilder } from 'spaceship-sprites'

// Creates a builder with default parameters
let builder = new SpriteBuilder({})

// Creates a builder with custom parameters
let custom = new SpriteBuilder({
    // The sprite painting area
    spriteDimensions: [9, 9],
    // The average blank pixels in the sprite
    blankPercentage: 0.7,
    // The color used in spots 'without' pixels
    blankColor: new Color(22, 22, 22),
    // The colors used when creating the sprite
    // Color accepts RGB from range [0, 255] or [0.0, 1.0]
    colorPallet: [new Color(20, 30, 40), new Color(0.1, 0.2, 0.3)],
    // Overrides colorPallet and is used only if useRandomPallet is true
    randomColorCount: 5,
    // If true, uses up to colorCount random colors
    useRandomPallet: true,
    // border in pixels, [up, right, down, left]
    border: [1, 2, 3, 4],
    // If true, ships will also be horizontally symmetrical
    horizontalSymmetry: true,
})

// Makes a single sprite
let sprite1 = builder.single().build()

// Makes a sprite and adds the border with blankColor color
let sprite2 = builder.single().withBorder().build()

// Adds a border until the sprite is of the specified dimension
let sprite3 = builder.single().withPadding([22, 22]).build()

SVG

new SpriteBuilder({}).single().withBorder().build().svg(100, 100)

The svg function will try to fit as best as possible the width and height. In this case, 100 became 108 to fit the sprite with dimensions 7 + 2 (sprite + border).

Creating svg might lead to some undesired stripes when the sprite dimensions aren't exactly divisible by the width and/or height:

new SpriteBuilder({spriteDimensions: [5, 7]}).single().withBorder().build().svg(100, 100)

To mitigate this, you might use withPadding to make the sprite square:

new SpriteBuilder({spriteDimensions: [5, 7]}).single().withPadding([9, 9]).build().svg(100, 100)

You can also use svgScale to set the dimension of each pixel:

new SpriteBuilder({spriteDimensions: [5, 7]}).single().withBorder().build().svgScale(1, 'em')

Sources