1.0.4 • Published 6 years ago

mixel v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

mixel

A rewrite of pixel-sprite-generator in Typescript.

Other changes:

  • Added ability to tint sprites
  • Added seedable RNG

Install

npm i mixel

Examples

See here for a list of visual examples.

Usage

Sample Usage

const SPACESHIP_MASK: Mask = {
  width: 6,
  height: 12,
  mirrorX: true,
  data: [
    0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 1, 1,
    0, 0, 0, 0, 1,-1,
    0, 0, 0, 1, 1,-1,
    0, 0, 0, 1, 1,-1,
    0, 0, 1, 1, 1,-1,
    0, 1, 1, 1, 2, 2,
    0, 1, 1, 1, 2, 2,
    0, 1, 1, 1, 2, 2,
    0, 1, 1, 1, 1,-1,
    0, 0, 0, 1, 1, 1,
    0, 0, 0, 0, 0, 0  
  ]
};

for(let i = 0; i < SPRITE_COUNT; i++) {
  const sprite = new Sprite(SPACESHIP_MASK, {
    colored: true
  });

  const canvas = createCanvas(sprite);
  document.getElementById('spaceship-default-settings').appendChild(canvas);
}

API

Mask

A Mask is the general shape of the generated object. It supports these parameters:

NameTypeDefaultDescription
widthnumber0The number of pixels wide the mask should be (if mirrorX is set, will be doubled).
heightnumber0The number of pixels tall the mask should be (if mirrorY is set, will be doubled).
mirrorXbooleanfalseWhether the mask should mirror across the Y axis (from left to right).
mirrorYbooleanfalseWhether the mask should mirror across the X axis (from top to bottom).
dataSpriteStructure[][]An array of values (-1..2) representing a SpriteStructure value.

SpriteOptions

SpriteOptions are specifically used in the manipulation of the sprite.

NameTypeDefaultDescription
coloredbooleanfalseWhether or not the sprite should have color.
edgeBrightnessnumber (0, 1)0.3How bright the edges of the sprite should be.
colorVariationsnumber (0, 1)0.2Higher numbers make the color variations within a sprite more frequent.
brightnessNoisenumber (0, 1)0.3Higher numbers make the brightness more "fuzzy" near the edge.
saturationnumber (0, 1)0.5Higher numbers make the general saturation of the image appear more colorful.
seedstringnoneThe seed to use for random generation. Using the same seed/mask will result in the same image every time.
tint{ r: number, g: number, b: number, a: number }noneThe tint to apply to the image when it's been generated.
randomSampleCallback(x: number, y: number) => SpriteStructureRandomly change 1/2 to -1/0The callback to be applied to each individual cell of the sprite.

More Usage

Check the editor here to see more examples.