npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

colorsmith

v1.0.9

Published

Create colors based on intuitive Chroma, Complexion and Coloration model.

Downloads

26

Readme

Colorsmith

Latest NPM release License

Color library based on Chroma-Complexion-Coloration (CCC) model

The aim of the project is to help create variations of base color and to fully exploit CCC model.

Chroma: If the chroma of red is 0, green is 1/3 and blue is 2/3 then the chroma for yellow is 1/6.

Complexion: The color code for yellow is #ffff00 which means it is twice brighter than red, #ff0000 or green #00ff00 alone.

Surface complexion: Even though yellow's color code is #ffff00 and red is only #ff0000, both have same surface complexion in the sense that they represent brightest color in their own directions as they lie on the surface of the color cube.

Coloration: It is analogous the the amount of color pigments. If diminished, the color is reduced to a shade of grey.

Installation

Node.js

colorsmith is available on npm. To install it, type:

$ npm install colorsmith

Usage

Import the library in your code and you can do basic transformations

const Cs = require('colorsmith')

var color = '#f07746'
var c = Cs.hex2surfCcc( color ) // Convert to surface CCC
var hexCode = Cs.surfCcc2hex( c ) // Convert back
hexCode == color // true

Alternatively, you can extract the CCC components and reconstruct the hex code with modified CCC components. The following example produces a yellow color with same surface complexion and coloration as the original color:

var [ chroma, complexion, coloration ] = Cs.hex2surfCcc( color )
hexCode = Cs.surfCcc2hex( [ 1/6, complexion, coloration ] )
hexCode == color // false, we changed chroma to yellow tint

If you do not want to use surface complexion, the following functions produce a yellow color with same complexion and coloration as the original color but the complexion is not automatically adjusted according to the color:

var [ chroma, complexion, coloration ] = Cs.hex2ccc( color )
hexCode = Cs.ccc2hex( [ 1/6, complexion, coloration ] )
hexCode == color // false, we changed chroma to yellow tint

Here's the summary of all available functions:

NOTE: All values are in the range [0,1], that is 0 ≤ x ≤ 1.



[ chroma, complexion, coloration ] = Cs.hex2ccc( '#e48c15' )
hexCode = Cs.ccc2hex( [ chroma, complexion, coloration ] )

[ chroma, complexion, coloration ] = Cs.rgb2ccc( [ red, green, blue ] )
[ red, green, blue ] = Cs.ccc2rgb( [ chroma, complexion, coloration ] )

[ chroma, surfComplexion, coloration ] = Cs.hex2surfCcc( '#e48c15' )
hexCode = Cs.surfCcc2hex( [ chroma, surfComplexion, coloration ] )

[ chroma, surfComplexion, coloration ] = Cs.rgb2surfCcc( [ red, green, blue ] )
[ red, green, blue ] = Cs.surfCcc2rgb( [ chroma, surfComplexion, coloration ] )

hexCode = Cs.rgb2hex( [ red, green, blue ] )
[ red, green, blue ] = Cs.hex2rgb( '#e48c15' )

surfComplexion = Cs.toSurfaceComplexion( chroma, complexion )
complexion = Cs.fromSurfaceComplexion( chroma, surfComplexion )

Here is the complete program that produces an output similar to the image above. You can run test and see the test.html file produced in the 'test' folder.

$ npm test

const Cs = require('colorsmith')

//Generate a random color
var color = (Math.random()*0xffffff<<0).toString(16)
while( color.length < 6 ) color = '0' + color
color = '#' + color

var [ chroma, complexion, coloration ] = Cs.hex2surfCcc( color )
var [ chroma1, complexion1, coloration1 ] = Cs.hex2ccc( color )

var result = '<!DOCTYPE html><meta charset="UTF-8"/><style>div { display: inline-block; width:8vw; height: 8vw; } </style><p>Base color</p><div style="background:'+color+'"></div><br/>'

result += '<p>Variation in surface chroma. Colors in the first row are guaranteed to have uniform brightness but not so in the second row.</p>'

for( var i = 0; i < 1; i+=0.1 ) {
  result += '<div style="background:'+Cs.surfCcc2hex([i,complexion,coloration])+'"></div>'
}

result += '<br/>'

for( var i = 0; i < 1; i+=0.1 ) {
  result += '<div style="background:'+Cs.ccc2hex([i,complexion1,coloration1])+'"></div>'
}

result += '<br/><p>Variation in surface complexion. Middle color in the first row is guaranteed to be the brightest color but not so in the second row. Variation in the second row is guaranteed to be uniform but not so in the first row.</p>'

for( var i = 0; i < 1; i+=0.1 ) {
  result += '<div style="background:'+Cs.surfCcc2hex([chroma,i,coloration])+'"></div>'
}

result += '<br/>'

for( var i = 0; i < 1; i+=0.1 ) {
  result += '<div style="background:'+Cs.ccc2hex([chroma1,i,coloration1])+'"></div>'
}

result += '<br/><p>Variation in coloration, only one row.</p>'

for( var i = 0; i < 1; i+=0.1 ) {
  result += '<div style="background:'+Cs.surfCcc2hex([chroma,complexion,i])+'"></div>'
}

result += '<br/>'

require('fs').writeFile( require('path').join( __dirname, 'test.html' ), result, err=>console.log(err) )

console.log( '*** NOTE: Don\'t forget to manually inspect test.html' )

Change log

releases