GithubHelp home page GithubHelp logo

3dhead / paint-by-number Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gakimball/paint-by-number

0.0 0.0 0.0 18 KB

๐ŸŽจ Color ASCII art with ease

License: MIT License

JavaScript 100.00%

paint-by-number's Introduction

Paint by Number

Color ASCII art with ease

Travis npm

Installation

npm install paint-by-number

Usage

Let's say you have a string like this:

Rainbow!

Now you create a template with a string of the same character length like this:

 0123456

Now you create a palette that maps ANSI colors to the numbers.

const palette = {
  0: 'red',
  1: 'yellow',
  2: 'green',
  3: 'cyan',
  4: 'blue',
  5: 'magenta',
  6: 'white'
}

Let's put it all together.

const paint = require('paint-by-number');

const input  = 'Rainbow!';
const template = ' 0123456';
const palette = {
  0: 'red',
  1: 'yellow',
  2: 'green',
  3: 'cyan',
  4: 'blue',
  5: 'magenta',
  6: 'white'
};

const output = paint(input, template, palette);
console.log(output);

API

paint(input, template, palette)

Colors the characters of a string (or an array of strings) based on a color map and palette. Returns the same string or array, but colored.

  • input (String or Array): string(s) to be painted.
  • template (String or Array): template to refer to when painting the input string. The structure of template should match that of input.
    • Every non-whitespace character in the color map is read and checked against the color palette. If a matching property is found in the color palette, the character in the input string is painted with the value of the property. Use whitespace to indicate that a character should not be colored, which means it will use the user's command line default.
  • palette (Object): Color palette to use when reading the template. The key is the character to use, and the value is the color to attach to that character. Any character can be a key, but a key must be a single character.

Characters are colored using chalk. Any function chalk has for coloring can be used as a palette color.

const palette = {
  0: 'red',
  1: 'bgRed'
}

It's also possible to override the default color by adding a one-space key to the palette.

const palette = {
  ' ': 'blue'
}

Local Development

git clone https://github.com/gakimball/paint-by-number
cd paint-by-number
npm install
npm test

License

MIT ยฉ Geoff Kimball

paint-by-number's People

Contributors

gakimball avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.