Code Monkey home page Code Monkey logo

Comments (3)

eljeffeg avatar eljeffeg commented on June 18, 2024

I was able to solve the first one by just doing this, which could perhaps be added as an example on how to seed the color if you don't include something for initialization:

var rcolor = new RColor;
rcolor.hue = .5;

On the second one, what I did was just save my value for each id, so there was no need to request it more than once. However, I was using it for a gradient, so it was important for me to call the same color again, but with a different saturation. So I did add this:

RColor.prototype.getAgain = function(hex,saturation,value) {
    if(typeof saturation !== "number")  saturation = 0.5;
    if(typeof value !== "number")       value = 0.95;
    var rgb = this.hsvToRgb(this.hue,saturation,value);
    if(hex)
        return "#" +  this.padHex(rgb[0].toString(16))
            + this.padHex(rgb[1].toString(16))
            + this.padHex(rgb[2].toString(16));
    else
        return rgb;
};

That allowed me to do this for creating my gradient:

var color1 = rcolor.get(true);
var color2 = rcolor.getAgain(true, 0.4, 0.99);

from randomcolor.

sterlingwes avatar sterlingwes commented on June 18, 2024

Thanks Jeff for the feedback, this makes sense to me and I'll look into working it in.

from randomcolor.

sterlingwes avatar sterlingwes commented on June 18, 2024

I know it's been a while but wanted to update this since I've recently reworked this library.

I thought about this some more and I think it should be the job of whatever code is leveraging rcolor to take care of saving or associating colors with IDs. The new API should make it easier for folks to override the hue, saturation and value options.

Going to focus on making sure this does one thing and one thing well (generating random colors). Appreciate you sharing your use case though!

from randomcolor.

Related Issues (4)

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.