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

battle-lines

v1.0.2

Published

Creates abstract images in the form of irregular rounded lines

Downloads

4

Readme

Battle-Lines

Battle-Lines is a library for generating abstract images in the form of irregular rounded lines, which can be export as PNG/dataURL. With seed support to allow you to create exact same pattern when ever you need.

Content

📦 Getting Battle-Lines
🏎 Quickstart
〽️ Modes
🧰 API/Config
🛠 Custom Modes & Renderer
🧾 License
👨🏼‍💻 Contributing
💬 About

Getting Battle-Lines

You can grab Battle-Lines with npm/yarn:

npm install --save battle-lines

or

yarn add battle-lines

or download the bundle (minified): releases page.

QuickStart

Browsers

        <canvas id="canvas" width="1000" height="500"></canvas>
        <script src=".\scripts\BattleLines.min.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function () {
                let canvas = document.getElementById('canvas');
                battleline = BattleLines.New(
                    new BattleLines.Config(
                        canvas.width,
                        canvas.height,
                        20,
                        BattleLines.ClashMode,
                        {
                            BattleFieldSize: 20,
                        },
                        BattleLines.CanvasRenderer,
                        {
                            Canvas: canvas,
                            ColourOne: '#4AD4B9',
                            ColourTwo: '#9D5CF2',
                        }
                    )
                );

                battleline.Next();
            });
        </script>

ES6

<script type="module">
            import * as bl from './node_modules/battle-lines/dist-esm/index.js';
            document.addEventListener('DOMContentLoaded', function () {
                let canvas = document.getElementById('canvas');
                let battleline = new bl.BattleLines(
                    new bl.Config(
                        canvas.width,
                        canvas.height,
                        20,
                        bl.ClashMode,
                        {
                            BattleFieldSize: 20,
                        },
                        bl.CanvasRenderer,
                        {
                            Canvas: canvas,
                            ColourOne: '#4AD4B9',
                            ColourTwo: '#9D5CF2',
                        }
                    )
                );
                battleline.Next();
            });
        </script>

Node Need the node-canvas package to use this via Node.

const fs = require('fs');
const bl = require('Battle-Lines');
const { createCanvas } = require('canvas');

const canvas = createCanvas(1000, 500);

let battlelines = new bl.BattleLines(
    new bl.Config(
        canvas.width,
        canvas.height,
        20,
        bl.ClashMode,
        {
            BattleFieldSize: 20,
        },
        bl.CanvasRenderer,
        {
            Canvas: canvas,
            ColourOne: '#ff0000',
            ColourTwo: '#00ff00',
        }
    )
);
battlelines.Next();
let buffer = battlelines.Export(bl.CanvasRendererExportOptions.NodeJs);
fs.writeFileSync('image.png', buffer);

Modes

There are three modes/patterns which you can use by default. They have separate configs so you can adjust how they are generated. Images below show the default settings. Docs

ClashMode ScatterMode PincerMode

API & Configuration

Api
Please find the documentation for the api here

Configuration
Please find the documentation for the different configuration options for both Modes and Renderers here

Custom Mode & Renderer

If the built in modes or renderers aren't to your liking you create your own. This is done by simply passing your own function in the config. Please refer to the docs for information on creating your own Modes and Renderers. There is options for both Typescript and Javascript.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Contributing

Pull requests and issues are welcome! For all contributions, please:

  1. Read the Contributing
  2. Search the existing issues and pull requests to make sure your contribution isn't a duplicate

Issues

If you're submitting a bug, please include the environment (browser/node) and relevant environment version(s) that you have encountered the bug in.

Pull Requests

Important: if you are submitting a pull request that does not address an open issue in the issue tracker, it would be a very good idea to create an issue to discuss your proposed changes/additions before working on them.

  1. Fork the repo on GitHub.
  2. Install dependencies with npm install
  3. Create a topic branch and make your changes.
  4. (Optional) Run npm run test to test your code with jasmine
  5. Run npm run build to make sure it complies
  6. Submit a pull request to merge your topic branch into master.

Developing You can use npm run tsc:w to start the typescript compiler and watch for changes. This will help to check for errors and keep unused code out of the library. I would recommend using the TextRenderer when developing a new Mode.

About The Project

I created this project out of the lack of no library (I could find) to generate this pattern. With the only other way would be manually via image/vector editor, which I didn't like, as making one simple change would take a long time. This plus seeing trianglify.io inspired me to make this project. This is my first library and public Github project so trianglify repo helped a lot with the docs. I hope some people will find this library useful.