Giter VIP home page Giter VIP logo

Comments (5)

bgrins avatar bgrins commented on May 24, 2024

Vladimir,
Thanks for tracking this down. Can you explain what input is failing for you, and what the expected behavior is so we can make sure it is fixed? I want to make sure that we can spec out what should happen with negative values so we can add it to the test suite.

from tinycolor.

timothyausten avatar timothyausten commented on May 24, 2024

Same thing here. Since color is measured on a circular scale, any increases or decreases in the value should just keep on going around the circle instead of going out-of-range.

For example, tinycolor.js should normalize an out-of-range value of 361 as just 1. Conversely, it should change -1 into 359. A very high number such as 721 should be just 1. My version is similar to Vladimir's, except it allows input values beyond 360. Fiddle.

return { h: ( m1 < 0 ? m1 % 360 + 360 : m1 % 360 ), s: match[2], l: match[3] };

P.S. I have been getting some mileage out of this library, and I love it. :)

from tinycolor.

bgrins avatar bgrins commented on May 24, 2024

Yes I think this is what CSS colors are doing: http://jsfiddle.net/dd1t8zvq/. From http://www.w3.org/TR/css3-color/#hsl-color: "As an angle, it implicitly wraps around such that -120=240 and 480=120".

@timothyausten would you be able create a pull request with your change and a small test case?

from tinycolor.

timothyausten avatar timothyausten commented on May 24, 2024

Pull request created.

from tinycolor.

yukulele avatar yukulele commented on May 24, 2024

According to this article https://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation
you can use floored division function:

modulo(x,y){
  return x - y * Math.floor(x / y)
}
tinycolor(h: modulo(hue, 360), s: 100, l: 50)

from tinycolor.

Related Issues (20)

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.