# dots-galaxy

> create basic procedural animation in canvas element

Latest version **1.0.1** (published 2022-03-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install dots-galaxy
pnpm add dots-galaxy
yarn add dots-galaxy
bun add dots-galaxy
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-03-13 |
| First published | 2022-03-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 51.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lúcio Carvalho Almeida |
| Maintainers | ninho |
| Keywords | procedural-animation, canvas |

## Links

- npm: https://www.npmjs.com/package/dots-galaxy
- Repository: https://github.com/LucioCarvalhoDev/dots-galaxy
- Homepage: https://github.com/LucioCarvalhoDev/dots-galaxy#readme
- Issues: https://github.com/LucioCarvalhoDev/dots-galaxy/issues
- npm.io page: https://npm.io/package/dots-galaxy

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-03-13
- 0.5.0 — 2022-03-10
- 0.1.1 — 2022-03-10

## README

# Dots Galaxy

Package for creation of simple and elegant customizable procedural animations like [this](https://luciocarvalhodev.github.io/dots/).

## Installation

`npm i dots-galaxy`

## Usage

```js
/* Basic Functions */

import CanvasController from "dots-galaxy";

const canvas = new CanvasController(document.getElementById("myCanvas"));

canvas.populate(30); // instance 30 dots with random props
canvas.renderDots(); // draw all dots in canvas
canvas.renderLines(); // draw lines that connect nearby points

// update positions of each dot based in velocity,
// diretion and current position
canvas.update();

/* Animate */

setInterval(function () {
  const population = canvas.step(); // update + render

  if (population < 30) {
    canvas.rePopulate(30 - population);
  } else {
    canvas.kill(population - 30);
  }
}, 30);
```

> Dot population will decay naturally, so it's necessary check the quantity and replace them

```js
/* Customization */

const rules = CanvasController.defaultRules();
/*
{
    screenMargin: 5,
    dotBornMode: 'randomChild',
    dotDirectionRange: [0, 359],
    dotColor: "#00ff00",
    dotFade: true,
    dotPopulation: 100,
    dotSize: 2.5,
    dotSpeed: 1,
    dotSpeedVariation: 0.5,
    lineColor: "#00ff00",
    lineFade: true,
    lineMaxLenght: 0,
};
*/

rules.dotPopulation = 200;
const canvas = new CanvasController(document.getElementById("myCanvas"), rules);
```

```js
/* Update Rules */
const canvas = new CanvasController(document.getElementById("myCanvas"));

const button = document.getElementById("increment");
button.onclick = () => {
  const curPopulation = canvas.rules.dotPopulation;
  canvas.setRules({ dotPopulation: curPopulation + 5 });
};
```

## Documentation

- [Docs](https://luciocarvalhodev.github.io/dots-galaxy)

---
_Source: https://npm.io/package/dots-galaxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
