项目作者: mster

项目描述 :
Generate color complements, shades, tints, and tones. Convert between color spaces.
高级语言: JavaScript
项目地址: git://github.com/mster/prismaek.git
创建时间: 2021-03-27T03:19:32Z
项目社区:https://github.com/mster/prismaek

开源协议:

下载


Prismaek License: MIT code style: prettier Build Status Coverage Status

Generate color complements, shades, tints, and tones. Convert between color spaces.

Install

  1. $ npm install prismaek

Usage

To produce complements, use the provided harmonies functions.

See Harmonies.

  1. const { harmonies } = require("prismaek");
  2. const hsv = { h: 153, s: 0.737, v: 0.596 };
  3. /* hue: 153 deg, saturation: 73.7%, value: 59.6% */
  4. const complementary = harmonies.complementary(hsv);
  5. /* [ { h: 153, s: 0.737, v: 0.596 }, { h: 333, s: 0.737, v: 0.596 } ] */

complementary

  1. const triadic = harmonies.triadic(hsv);
  2. /* [ { h: 153, s: 0.737, v: 0.596 },
  3. { h: 273, s: 0.737, v: 0.596 },
  4. { h: 33, s: 0.737, v: 0.596 } ] */

triadic

  1. const analagous = harmonies.analagous(hsv);
  2. /* [ { h: 153, s: 0.737, v: 0.596 },
  3. { h: 183, s: 0.737, v: 0.596 },
  4. { h: 213, s: 0.737, v: 0.596 },
  5. { h: 243, s: 0.737, v: 0.596 } ] */

analagous

To explicitly change between color spaces, use the conversion utilities.

See Utilities.

  1. const { utils } = require("prismaek");
  2. const rgb = { r: 75, g: 21, b: 156 };
  3. const hsv = utils.rgb2HSV(rgb);
  4. /* { h: 264, s: 0.865, v: 0.612 } */

Validate color spaces

  1. const hsvSpace = utils.isHSV(hsv);
  2. /* true */
  3. const badHSV = { h: 361, s: 1.001, v: -0.001 };
  4. const notHsvSpace = utils.isHSV(badHSV);
  5. /* false */

Get the color space of a color, using cspace.

  1. const { cspace } = utils;
  2. const color = { h: 312, s: 0.431, l: 0.213 };
  3. const colorSpace = cspace(color);
  4. /* "hsl" */

Dynamically transform color spaces using xspace.

  1. const { xspace } = utils;
  2. const colors = [
  3. { r: 75, g: 21, b: 156 },
  4. "#4b159c",
  5. { h: 264, s: 0.865, v: 0.612 },
  6. { h: 264, s: 0.763, l: 0.347 },
  7. ];
  8. const rgbColors = colors.map((color) => xspace(color, "rgb"));
  9. /* [ { r: 75, g: 21, b: 156 },
  10. { r: 75, g: 21, b: 156 },
  11. { r: 75, g: 21, b: 156 },
  12. { r: 75, g: 21, b: 156 } ] */

API

Harmonies

  1. harmonyName (base [, format])
  2. - base: <Object> | <String> Base color.
  3. - format: <String> Output color space, defaulting to "hsv".
  4. - Returns: <Array<<Object> | <String>> The generated harmony, including the base color.

Generates mathematically proven color harmonies.

  1. const {
  2. harmonies: { complementary },
  3. } = require("prismaek");
  4. complementary({ r: 40, g: 102, b: 106 }, "hex");
  5. complementary("#009197");

Effects

  1. effectName (base [, format] [, step] [, count])
  2. - base: <Object> | <String> | <Array> Base color, or array of colors.
  3. - format: <String> Output color space, defaulting to "hex".
  4. - step <Number> Step size when generating the effect, a number between 0 and 1. Default is 0.10, or 10%.
  5. - count <Number> Iteration count, defaulting to 5.
  6. - Returns: <Array<<Object> | <String>> The generated effect, including base color.

Generates a color scheme based on popular effects.

  1. const {
  2. effects: { shade, tint, tone },
  3. } = require("prismaek");
  4. shade("#ee0a97", "rgb", 0.05, 10);
  5. tint({ r: 40, g: 65, b: 106 }, "hex");
  6. tone({ h: 359, s: 0.102, l: 0.696 });

Utilities

xspace

  1. xspace (color, map)
  2. - color <Object> | <String> Base color.
  3. - map <String> Color space to convert to.
  4. - Returns: <Object> | <String> The converted color.

Converts between supported color spaces.

  1. const {
  2. utils: { xspace },
  3. } = require("prismaek");
  4. xspace("#ee0a97", "rgb"); // { r: 238, g: 10, b: 151 }

cspace

  1. cspace (color)
  2. - color <Object> | <String> Base color.
  3. - Returns <String> color space.

Returns the color space of a color or null.

  1. const {
  2. utils: { cspace },
  3. } = require("prismaek");
  4. cspace("#d5186c"); // "hex"
  5. cspace({ h: 251, s: 0.891, v: 0.668 }); // "hsv"
  6. cspace({ foo: "bar" }); // null

\2\

  1. <from-space>2<TO-SPACE> (color)
  2. - color <Object> | <String> Base color.
  3. - Returns <Object> | <String> The converted color.

Useful when explicity converting from one color space to another.

  1. const {
  2. utils: { rgb2Hex, hex2RGB },
  3. } = require("prismaek");
  4. const hex = rgb2Hex({ r: 163, g: 189, b: 254 }); // #a3bdfe
  5. hex2RGB(hex); // { r: 163, g: 189, b: 254 }

Contributing

See our guidelines