svelte-animated-pixels
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

Svelte Animated Pixels

This library provides an easy way to create pixelated canvas animations by just declaring maps of pixels a strings.

Install with:

npm i -D svelte-animated-pixels

Then start drawing, the idea is pretty simple

  • x delimits a pixel to be drawn.
  • . delimits the background.
  • Any other character that's not x or . is safely ignored.
<style>
  .wrapper {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: grid;
    justify-items: center;
    align-items: center;
    background: black;
  }
</style>
<script>
  import { Animated, PixelMap } from 'svelte-animated-pixels';
  const FRAMES = [
    `
    . x . . . . . x .
    . . x . . . x . .
    . . x x x x x . .
    . x x x x x x x .
    . x x x x x x x .
    . . x x x x x . .
    . x . . . . . x .
    . . x . . . x . .
    `,
    `
    . . . x . x . . .
    . . x . . . x . .
    . . x x x x x . .
    . x x x x x x x .
    . x x x x x x x .
    . . x x x x x . .
    . . x x . x x . .
    . . . . . . . . .
    `
  ];
</script>

<div class="wrapper">
  <Animated frames={FRAMES} let:using={{ map }}>
    <PixelMap scale={5} {map} />
  </Animated>
</div>

Peek 2024-04-28 23-54

[!NOTE] Once a frame has been drawn on a pixel map, all subsequent drawn frames MUST have the same shape, meaning both width and height MUST match.

Planned Features

Feature Implemented
Draw pixels using declarative maps of strings ✅ Done - <PixelMap/>
Created animations from list of maps ✅ Done - <Animated/>
Fine tune each pixel's color ✖ WIP

Readme

Keywords

none

Package Sidebar

Install

npm i svelte-animated-pixels

Weekly Downloads

0

Version

0.1.3

License

none

Unpacked Size

17.2 kB

Total Files

22

Last publish

Collaborators

  • loopcake