TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

RandomColor – a color generator for JavaScript

137 pointsby dmerfieldalmost 11 years ago

15 comments

mxfhalmost 11 years ago
Good library to begin with, but could do better on the perceived brightness.<p>Since HSV is NOT perceived as evenly distributed to the human eye along the value(lightness) axis[1],<p>would recommend employing <i>chroma.js</i>[2] which uses the HCL and CIE color spaces, which in general yield more pleasing results for use in color scales.<p>[1] <a href="http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/" rel="nofollow">http:&#x2F;&#x2F;vis4.net&#x2F;blog&#x2F;posts&#x2F;avoid-equidistant-hsv-colors&#x2F;</a><p>[2] <a href="https://github.com/gka/chroma.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gka&#x2F;chroma.js</a><p><i>i want hue</i> might be a bit of overkill though: <a href="http://tools.medialab.sciences-po.fr/iwanthue/index.php" rel="nofollow">http:&#x2F;&#x2F;tools.medialab.sciences-po.fr&#x2F;iwanthue&#x2F;index.php</a>
评论 #7825045 未加载
评论 #7824822 未加载
riffraffalmost 11 years ago
Maybe of interest: colorbrewer palettes as included in D3.js, which is my goto choice for colors<p><a href="http://bl.ocks.org/mbostock/5577023" rel="nofollow">http:&#x2F;&#x2F;bl.ocks.org&#x2F;mbostock&#x2F;5577023</a><p><a href="https://github.com/mbostock/d3/tree/master/lib/colorbrewer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mbostock&#x2F;d3&#x2F;tree&#x2F;master&#x2F;lib&#x2F;colorbrewer</a>
loopdoendalmost 11 years ago
A really important thing for data-vis is generating distinguishably different random colors. It&#x27;d be great to have a library that produces series of distinguishable, pleasing colors.
评论 #7825603 未加载
评论 #7824906 未加载
评论 #7825601 未加载
jbranchaudalmost 11 years ago
Would it be possible to add a seed option so that you could request the same set of random colors if needed?
评论 #7824811 未加载
评论 #7824905 未加载
enscralmost 11 years ago
Related : &quot;How to Generate Random Colors Programmatically&quot;<p><a href="http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/" rel="nofollow">http:&#x2F;&#x2F;martin.ankerl.com&#x2F;2009&#x2F;12&#x2F;09&#x2F;how-to-create-random-col...</a>
bilalqalmost 11 years ago
This is actually really cool. I can think of several practical applications for this.
heydenberkalmost 11 years ago
I wrote a general purpose (pseudo-)random value generation library[0] that does random color generation[1] among lots of other capabilities. It&#x27;d be interesting to see how you could use the mutator to implement some of this functionality.<p>[0] <a href="https://github.com/heydenberk/stochator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;heydenberk&#x2F;stochator</a> [1] <a href="https://github.com/heydenberk/stochator#from-predefined-sets" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;heydenberk&#x2F;stochator#from-predefined-sets</a>
calineczkaalmost 11 years ago
I went with the approach of hardcoding few sets generated by <a href="http://tools.medialab.sciences-po.fr/iwanthue/" rel="nofollow">http:&#x2F;&#x2F;tools.medialab.sciences-po.fr&#x2F;iwanthue&#x2F;</a> (which i think already been covered on HN) in my app. Just one set when i need &lt;= 5 colors, one for &lt;= 20, 50 and 100. Oh, and alternative set with different palette of colors when I need two diagrams on the same page. As a colorblind person I must say I was very happy with the results.
leeoniyaalmost 11 years ago
&quot;BRIGHT COLORS&quot; and &quot;DARK COLORS&quot; overlap with several dark colors. pretty much every color model gets brightness values that dont jive with perceptual reality.
rhubarbcustardalmost 11 years ago
This produces really nice colour sets, I&#x27;ll definitely be using this to generate some backgrounds for blog posts. Nice work and thanks for sharing.
bikamonkialmost 11 years ago
Great job! I know need not to worry about font color just pick one that reads fine for a given hue.
hcarvalhoalvesalmost 11 years ago
Supporting complementary &#x2F; tertiary colors would make it even more useful.
sideprojectalmost 11 years ago
really like it. did some research before on how to generate colours that would be good for some simple visualizations, but found it difficult. This is great for a quick retrieval of colours that you can use!
betadreameralmost 11 years ago
Neat! I would love to see the math behind it.
评论 #7824847 未加载
kanakiyajayalmost 11 years ago
Anyone looking for a single line code to generate a random hex color: var randomColor = Math.floor(Math.random()*16777215).toString(16);
评论 #7825673 未加载