Comments (4)
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.
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.
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.
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)
- Returns an array containing sometimes the same colors HOT 1
- make_scheme() 'mono', actually renders 4 colors instead of 5 HOT 4
- Bump npm to newest version HOT 1
- Question: Lite version?
- make_color() returns "#00000.randomhex" when base_color: black HOT 1
- Better Documentation
- Change the dist file name with `.min.` suffix
- Documentation about colors_returned=1 says you only get one, I expected a string HOT 3
- greyscale: true generates ["#000000.36cd673"]
- How do i get color by opacity HOT 1
- Please publish to NPM HOT 1
- Add Plz mode
- Generate Material Design shades from single color
- human distinguishable
- Colours returned are waaay too long for HEX! HOT 1
- Invalid conversion rgb-hsv
- Domain Expired HOT 1
- Any way to fork and create website? HOT 8
- Archive?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pleasejs.