Giter Club home page Giter Club logo

Comments (4)

csauve avatar csauve commented on June 30, 2024

I was also looking for such a feature! I ended up generating a pseudo-random from my seed mod 360, and using that as the hue parameter.

from pleasejs.

atomgomba avatar atomgomba commented on June 30, 2024

I'm glad I've found this ticket, I had the same idea for improvement. Currently I'm using this function to do this task:

colorCache = {}

get_color = (seed) ->
    if not (seed of colorCache)
        colorCache[seed] = Please.make_color()
    return colorCache[seed]

But the problem is that this will increase memory usage as the colorCache object grows. The real solution would be to extend PleaseJS so it could generate the same color based on a value.

from pleasejs.

tuckwat avatar tuckwat commented on June 30, 2024

I also am using the hue value to generate constant colors based on a String. I'm using the hash function here:
http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/

and passing it into the hue property like so:

var colorSeed = Math.abs(hash) % 360;
var color = ColorUtil.make_color({golden: false,
   hue: colorSeed,
   saturation: 0.7,
   value: 0.8
});

Seems to be working well for my use case but only generates 360 unique colors. Probably a good idea to use memoization if calling it frequently.

from pleasejs.

Kronuz avatar Kronuz commented on June 30, 2024

You can already do this, use the seed option for make_color(); for example:

> Please.make_color({seed: 'some_string_must_be_string'});
[ '#72a0bf' ]

from pleasejs.

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.