• Stars
    star
    644
  • Rank 69,893 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Esoteric Palette Generator Mico-Lib Interpolating HSL Color in cartesian space

poline

Esoteric Color palette Generator Mico-Lib

"poline" is an enigmatic color palette generator, that harnesses the mystical witchcraft of polar coordinates. Its methodology, defying conventional color science, is steeped in the esoteric knowledge of the early 20th century. This magical technology defies explanation, drawing lines between anchors to produce visually striking and otherworldly palettes. It is an indispensable tool for the modern generative sorcerer, and a delight for the eye.

Poline DEMO UI

Summoning

The use of "Poline" begins with the invocation of its command, which can be performed with or without arguments. If called without, the tool will generate a mesmerizing palette featuring two randomly selected anchors. On the other hand, one can choose to provide their own anchor points, represented as a list of hsl values, for a more personal touch. The power to shape and mold the colors lies in your hands."

new Poline({
  anchorColors: [
    [309, 0.72, 0.80],
    [67, 0.32, 0.08],
    //...
  ],
});

Points

The magic of "Poline" is revealed through its technique of drawing lines between anchor points. The richness of the palette is determined by the number of points, with each connection producing a unique color.

Increasing the number of points will yield an even greater array of colors. By default, four points are used, but this can easily be adjusted through the 'numPoints' property on your Poline instance, as demonstrated in the code example.

new Poline({
  numPoints: 6,
});

The resulting palette is a product of points multiplied by the number of anchor pairs. It can be changed after initialization by setting the numPoints property on your "Poline" instance.

Anchors

At the heart of "Poline" lies the concept of anchors, the fixed points that serve as the foundation for the creation of color palettes. Anchors are represented as a list of hsl values, which consist of three components: hue [0…360], saturation [0…1], and lightness [0…1].

The choice is yours, whether to provide your own anchor points during initialization or to allow "Poline" to generate a random selection for you by omitting the 'anchorColors' argument. The versatility of Poline extends "Poline" its initial setup, as you can also add anchors to your palette at any time using the 'addAnchor' method. This method accepts either a color as HSL array values or an array of X, Y, Z coordinates, further expanding the possibilities of your color creation.

poline.addAnchorPoint({
  color: [100, 0.91, 0.80]
});

// or

poline.addAnchorPoint({
  xyz: [0.43, 0.89, 0.91]
});

Updating Anchors

With this feature, you have the power to fine-tune your palette and make adjustments as your creative vision evolves. So whether you are looking to make subtle changes or bold alterations, "Poline" is always ready to help you achieve your desired result.

The ability to update existing anchors is made possible through the 'updateAnchorPoint' method. This method accepts the reference to the anchor you wish to modify and either a color in the form of HSL representation or an XYZ position array.

poline.updateAnchorPoint({
  point: poline.anchorPoints[0],
  color: [286, 0.22, 0.22]
});

Position Function

The position function in "Poline" plays a crucial role in determining the distribution of colors between the anchors. It works similar to easing functions and can be imported from the "Poline" module.

A position function is a mathematical function that maps a value between 0 and 1 to another value between 0 and 1. By definition the same position function for all axes "Poline" will draw a straight line between the anchors. The chosen function will determine the distribution of colors between the anchors.

import {
Poline, positionFunctions
} from 'poline';

new Poline({
  positionFunction: 
    positionFunctions.linearPosition,
});

If none is provided, "Poline" will use the default function, which is a sinusoidal function. The following position functions are available and can be included by importing the positionFunctions object from the "Poline" module:

  • linearPosition
  • exponentialPosition
  • quadraticPosition
  • cubicPosition
  • quarticPosition
  • sinusoidalPosition (default)
  • asinusoidalPosition
  • arcPosition

Arcs

By defining different position functions for each axis, you can control the distribution of colors along each axis (positionFunctionX, positionFunctionY, positionFunctionZ). This will draw different arcs and create a diverse range of color palettes.

new Poline({
  positionFunctionX: 
    positionFunctions.sinusoidalPosition,
  positionFunctionY: 
    positionFunctions.quadraticPosition,
  positionFunctionZ: 
    positionFunctions.linearPosition,
});

Palette

By default, the palette is not a closed loop. This means that the last color generated is not the same as the first color. If you want the palette to be a closed loop, you can set the closedLoop argument to true.

poline.closedLoop = true;

It is also possible to close the loop after the fact by setting poline.closedLoop = true|false.

Hue Shifting

With the power of hue shifting, "Poline" provides yet another level of customization. This feature allows you to shift the hue of the colors generated by a certain amount, giving you the ability to animate your palette or create similar color combinations with different hues."

"poline" supports hue shifting. This means that the hue of the colors will be shifted by a certain amount. This can be useful if you want to animate the palette or generate a palette that looks similar to your current palette but using different hues.

poline.shiftHue(1);

The amount is a int or float between -Infinity and Infinity. It will permanently shift the hue of all colors in the palette.

Closest Anchor

In some situations, you might want to know which anchor is closest to a certain position or color. This method is used in the visualizer to highlight to select the closest anchor on click.

poline.getClosestAnchorPoint(
  {xyz: [x, y, null], maxDistance: .1}
)

The maxDistance argument is optional and will return null if the closest anchor is further away than the maxDistance. Any of the xyz or hsl components can be null. If they are null, they will be ignored.

Color List

The 'poline' instance returns all colors as an array of hsl arrays or alternatively as an array of CSS strings.

poline.colors
poline.colorsCSS

Remove Anchors

To remove an anchor, you can use the removeAnchorPoint method. It either takes an anchor reference or an index as an argument.

poline.removeAnchorPoint({
  point: poline.anchorPoints[
    poline.anchorPoints.length - 1
  ]
});
  // or
poline.removeAnchorPoint({
  index: poline.anchorPoints.length - 1
});

Color Model

To keep the library as lightweight as possible, "poline" only supports the hsl color model out of the box. However, it is easily possible to use other color models by using a library like culori.

import {Poline} from "poline";
import {formatHex} from "culori";
const poline = new Poline(/** options */);

const OKHslColors = [...poline.colors].map(
  c => formatHex({ 
    mode: 'okhsl', 
    {
      h: c.hsl[0], 
      s: c.hsl[1], 
      l: c.hsl[2]}
  })
);
const LCHColors = [...poline.colors].map(
  c => formatHex({ 
    mode: 'lch', 
    { 
      h: hsl[0],
      c: hsl[1] * 51.484,
      l: hsl[2] * 100,  
    }
  })
);

Installation

"poline" is available as an npm package. Alternatively you can clone it on GitHub.

npm install poline

You can also use the unpkg CDN to include the library in your project. I recommend using the mjs version of the library. This will allow you to use the import syntax. But you can also use the umd version if you prefer to use the script tag.

import { 
  Poline 
} from 'https://unpkg.com/poline?module'

License

And thus, the tome of "poline" has been written. Its mystical powers, steeped in the arcane knowledge of the ancients, now reside within these pages. May this compendium serve you in your quest for the ultimate color palette.

The project is MIT licensed and open source. If you find any bugs or have any suggestions please open an issue on GitHub.

Inspired and created with the blessing of Anatoly Zenkov

More Repositories

1

color-names

Large list of handpicked color names 🌈
JavaScript
2,282
star
2

fettepalette

Color ramp generator using curves within the HSV color model
TypeScript
147
star
3

farbvelo

"Random" color palette generator, cycles
JavaScript
67
star
4

rampensau

Color palette generation function using hue cycling and simple easing functions.
TypeScript
53
star
5

gotAnewDesignerMac

automate installation of a MAC for a designer
Ruby
47
star
6

color-name-api

Rest API that returns a bunch of color names for a given color-value
JavaScript
45
star
7

sensible

Maintain media-queries where they belong; in the SASS/SCSS and make them available with the same name space in your JS without polluting your HTML.
SCSS
25
star
8

ClosestVector

Find the closest Number / Vector / VectorN ∆
JavaScript
23
star
9

mod_autoindex.oh

Visual enhancement for apache's directory listing.
HTML
23
star
10

palette-aldente

Color palette curation and sharing tool
JavaScript
18
star
11

ticktack.js

requestanimationframe based watch.
JavaScript
17
star
12

bonescss

SCSS/CSS starting-point for every project. Mixes smacss namespaced h5bp things with other stuff I use all the time. It includes all the nice things from H5BP nicely namespaced using SMACSS
CSS
15
star
13

paletter

semantic color name/palette helper
JavaScript
14
star
14

dialog-size

A relative size palette
CSS
14
star
15

dotfiles

I stole my dotfiles all over the place, thank you internet ❤️ 🌎
Shell
10
star
16

elastiq

Elastiq website
HTML
9
star
17

colorparrot-twitter-bot

A bot that tweets random colors and lets you invent new ones
JavaScript
7
star
18

myMindColors

color palettes from https://access.mymind.com/colors
JavaScript
6
star
19

color-name-lists

A collection of color name lists
JavaScript
6
star
20

dialog-typography

Provides a central place to manage typography across multiple breakpoints.
SCSS
6
star
21

cga

Color Palette Generation Assistant
JavaScript
5
star
22

copic-colors

Up to date list of copic colors
JavaScript
5
star
23

sassvg-arrows

generates SVG-Arrows with sass. Large ones, Small ones, red ones.
CSS
4
star
24

sanzoWadaColors

Color palettes from Sanzo Wada's Color Book
JavaScript
4
star
25

dialog-settings

A simple key value store for module settings, to make modules more portable. With the nice side-effect that all settings can be output as native CSS variables.
CSS
4
star
26

webrings

a modern take on webrings
3
star
27

raumgleiter

Raumgleiter Website
Vue
3
star
28

lifx-js

very simple node.js server with sockets to play around with lifx bulbs
JavaScript
2
star
29

waypoint-animation

know if your DOM things are visible or not
JavaScript
2
star
30

color-fanfare

A collection of palettes that I like to reuse
2
star
31

noms-de-couleur

Recueil de noms de couleur en français.
HTML
2
star
32

scroll-width

Tiny optional AMD that returns the browsers scrollbar width
JavaScript
2
star
33

farbnamen

HTML
2
star
34

exalt.biz

http://exalt.biz website
SCSS
1
star
35

cockadoo

A twitter color experiment
1
star
36

color-fan

a pretty color fan
JavaScript
1
star
37

color-roulette

color palette generator function based mainly on chroma.js
1
star
38

wikipedia-color-names

Up to date list of wikipedia color names
HTML
1
star
39

nombres-de-colores

Una lista de nombres de colores en español.
HTML
1
star
40

z43

z43 collective website
HTML
1
star
41

battery-saver

Switches to power-saving Screensaver when not connected to power
Shell
1
star