GithubHelp home page GithubHelp logo

wessberg / color Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 211 KB

A library of well-tested helper methods for working with colors.

License: MIT License

TypeScript 99.28% JavaScript 0.72%
color hsl hsla rgba rgb hex darken lighten saturate random

color's People

Contributors

nmn avatar wessberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nmn

color's Issues

lighten('black') is still black

Hi Frederik, thanks for creating this library - I'm currently using it in a TypeScript project and the API is really nice.

I'm trying to lighten a black color, but it remains black:

const {lighten} = require("@wessberg/color")
console.log(lighten('black', 10)) // => '#000000'
console.log(lighten('#000000', 10)) // => '#000000'

(check it out on Runkit)

It works just fine for other colors.

I had a look at the source for lightenHsl, and the lightness is calculated as follows:

Math.max(0, Math.min(100, ((100 + percentage) * parseFloat(L)) / 100))

(where percentage = 10)

For black, L = 0, so the resulting lightness value is 0.
For L = 50, the resulting lightness is 55.

In general, it seems strange that the percentage is proportional to the existing lightness value, because colors that are already light will become much lighter than darker colors. I expected the lightness to simply be added to the existing lightness, ie. that

for L = 0, the resulting lightness would be 10,
and for L = 50 it would be 60.

in JS:

Math.max(0, Math.min(100, parseFloat(L) + percentage))

This change would obviously affect all of the colors generated by your library so I don't know if this is something you'd want to do if you're relying on the way specific colors look already - just wanted to flag this as I'll unfortunately have to use a different library for the time being.

Anyway let me know if this makes sense & if you'd consider changing the behavior. Thanks a lot :)

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.