0.0.1 • Published 8 years ago

color-classifier v0.0.1

Weekly downloads
3
License
MIT
Repository
-
Last release
8 years ago

color-classifier.js

Build Status npm version David License

Classify the color along the reference color. using algorithm the CIEDE2000, RGB, HSV.

Playground

Playground Screenshot

Playground

INSTALL

$ npm install color-classifier --save

or

Download the color-classifier.min.js.

USAGE

The following is the basic usage.

import ColorClassifier from "color-classifier"

const palette = ["#fff", "#000"];
const colorClassifier = new ColorClassifier(palette);
const color = colorClassifier.classify("#fefefe");

console.log(color); // {r: 255, g: 255, b: 255}

The type of pallet and algorithms have been some available.

import ColorClassifier, { Palette, AlgorithmTypes } from "color-classifier"

const colorClassifier = new ColorClassifier(Palette.W3C, AlgorithmTypes.HSV);
const color = colorClassifier.classify("#fefefe");

console.log(color); // {r: 255, g: 255, b: 255}

The available values are as follows.

Palette

The following is the palette list of preset.

Palette.W3C

hexcolor
#000000npm.io
#808080npm.io
#c0c0c0npm.io
#ffffffnpm.io
#800000npm.io
#ff0000npm.io
#008000npm.io
#00ff00npm.io
#808000npm.io
#ffff00npm.io
#008080npm.io
#00ffffnpm.io
#000080npm.io
#0000ffnpm.io
#800080npm.io
#ff00ffnpm.io

Palette.RAINBOW

hexcolor
#000000npm.io
#808080npm.io
#ffffffnpm.io
#ff0000npm.io
#ffa500npm.io
#ffff00npm.io
#008000npm.io
#00ffffnpm.io
#0000ffnpm.io
#800080npm.io

AlgorithmTypes

The difference algorithm of color is possible some selection.
Please try in Playground for the difference of each algorithm.

valuedescription
AlgorithmTypes.CIEDE2000Using the CIE Delta E 2000 Color-Difference algorithm (CIEDE2000).The CIEDE2000 color-difference formula,Color difference - Wikipedia, the free encyclopedia
AlgorithmTypes.HSVUsing the HSV color space.HSL and HSV - Wikipedia, the free encyclopedia
AlgorithmTypes.RGBUsing the RGB color space.RGB color model - Wikipedia, the free encyclopedia

API

new ColorClassifier(palette = Palette.W3C, algorithmType = AlgorithmTypes.CIEDE2000)

palette: {Array}
algorithmType: {String}

Palette is specify array in RGB object or HEX string.

HEX String:

const palette = ["#fff", "#000"];
const colorClassifier = new ColorClassifier(palette);

RGB Object:

const palette = [
  {r: 255, g: 255, b: 255},
  {r: 0,   g: 0,   b: 0}
];
const colorClassifier = new ColorClassifier(palette);

classify(color, format = "rgb")

color: {Object || String}
format: {String} ("rgb", "hex", "hsv")

Classifies the specified color along the palette.

const color1 = {r: 255, g: 255, b: 255};

console.log(colorClassifier.classify(color1, "rgb")); //{r: 255, g: 255, b: 255}
console.log(colorClassifier.classify(color1, "hex")); //#ffffff
console.log(colorClassifier.classify(color1, "hsv")); //{h: 0, s: 0, v: 100}


const color2 = "#fff";

console.log(colorClassifier.classify(color2, "rgb")); //{r: 255, g: 255, b: 255}
console.log(colorClassifier.classify(color2, "hex")); //#ffffff
console.log(colorClassifier.classify(color2, "hsv")); //{h: 0, s: 0, v: 100}

classifyFromArray(colors, format = "rgb")

colors: {Array}
format: {String} ("rgb, "hex", "hsv")

Classifies the specified array of colors along the palette.

const colors = ["#fefefe", "#fafafa", "#010101", "#020202"];
const results = colorClassifier.classifyFromArray(colors, "hex");

console.log(results);
// [
//   {
//     palette: "#ffffff",
//     colors: [
//       "#fefefe",
//       "#fafafa"
//     ]
//   },
//   {
//     palette: "#000000",
//     colors: [
//       "#010101",
//       "#020202"
//     ]
//   }
// ]

More APIs

  • setPalette(palette)
  • getPalette()
  • setAlgorithmType(algorithmType)
  • getAlgorithmType()

LICENCE

Released under the MIT Licence

AUTHOR

tsuyoshiwada

DEVELOPMENT

Initialization of the project.

$ cd /your/project/dir
$ git clone https://github.com/tsuyoshiwada/sweet-scroll.git

Install some dependencies.

$ npm install

Start the development. You can access to the http://localhost:3000/.

$ npm start

Run lint and testing.

$ npm test

Generates build file.

$ npm run build

Bugs, feature requests and comments are more than welcome in the issues