GithubHelp home page GithubHelp logo

arielsalminen / coloralgorithm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lyft/coloralgorithm

0.0 1.0 0.0 10 KB

Javacript function to produce color sets

License: Apache License 2.0

JavaScript 100.00%

coloralgorithm's Introduction

coloralgorithm

A JavaScript function for producing color sets. Used to build Lyft's color system (Spectrum) and power ColorBox.

Background

Usage

The function takes in a JavaScript object with a specs key that describes the properties of the desired color palette:

import generate from "./src/generate";

const input = {
  specs: {
    // Number of colors
    steps: 11,
    // Hue Start Value (0 - 359)
    hue_start: 315,
    // Hue End Value (0 - 359)
    hue_end: 293,
    // Hue Curve (See Curves Section)
    hue_curve: "easeInQuad",
    // Saturation Start Value (0 - 100)
    sat_start: 4,
    // Saturation End Value (0 - 100)
    sat_end: 90,
    // Saturation Curve (See Curves Section)
    sat_curve: "easeOutQuad",
    // Saturation Rate (0 - 200)
    sat_rate: 130,
    // Luminosity Start Value (0 - 100)
    lum_start: 100,
    // Luminosity End Value (0 - 100)
    lum_end: 53,
    // Luminosity Curve (See Curves Section)
    lum_curve: "easeOutQuad",
    // Modifier Scale
    // Every generated color gets a modifier (label) that
    // indicates its lightness. A value of 10 results in
    // two-digit modifiers. The lightest color will be 0 (e.g. Red 0)
    // and the darkest color will be 100 (e.g. Red 100), given
    // that you generate 11 colors
    modifier: 10
  }
};

const palette = generate(input);

Contrary to ColorBox, this version of the algorithm does not support a lock color.

Example Output

The function returns the generated palette as an array of color objects:

[
  {
    contrastBlack: "19.32",
    contrastWhite: "1.09",
    displayColor: "black",
    hex: "#fff2fc",
    hsl: [315, 1, 0.974],
    hsv: [314.99999999999994, 0.052000000000000074, 1],
    hue: 314.99999999999994,
    hueRange: [315, 293],
    label: 0,
    lum: 1,
    rgb: [255, 242, 252],
    sat: 0.052000000000000074,
    steps: 11
  },
  ...
];

Curves

Hue, Saturation, and Luminosity all allow you to specify a curve. The following curves are supported:

  • easeInQuad (Quad - EaseIn)
  • easeOutQuad (Quad - EaseOut)
  • easeInOutQuad (Quad - EaseInOut)
  • easeInQuart (Quart - EaseIn)
  • easeOutQuart (Quart - EaseOut)
  • easeInOutQuart (Quart - EaseInOut)
  • easeInSine (Sine - EaseIn)
  • easeOutSine (Sine - EaseOut)
  • easeInOutSine (Sine - EaseInOut)
  • easeInCubic (Cubic - EaseIn)
  • easeOutCubic (Cubic - EaseOut)
  • easeInOutCubic (Cubic - EaseInOut)
  • easeInExpo (Expo - EaseIn)
  • easeOutExpo (Expo - EaseOut)
  • easeInOutExpo (Expo - EaseInOut)
  • easeInQuint (Quint - EaseIn)
  • easeOutQuint (Quint - EaseOut)
  • easeInOutQuint (Quint - EaseInOut)
  • easeInCirc (Circ - EaseIn)
  • easeOutCirc (Circ - EaseOut)
  • easeInOutCirc (Circ - EaseInOut)
  • easeInBack (Back - EaseIn)
  • easeOutBack (Back - EaseOut)
  • easeInOutBack (Back - EaseInOut)
  • linear (linear)

coloralgorithm's People

Contributors

asottile avatar k-vyn avatar lyft-metaservice avatar soffes avatar vincentmvdm avatar

Watchers

 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.