randomcolor
Advanced tools
Comparing version 0.5.3 to 0.5.4
{ | ||
"name": "randomcolor", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "A tiny script for generating attractive random colors", | ||
@@ -10,14 +10,21 @@ "main": "randomColor.js", | ||
}, | ||
"keywords": ["attractive", "random", "color", "generator"], | ||
"files": [ | ||
], | ||
"keywords": [ | ||
"attractive", | ||
"random", | ||
"color", | ||
"generator" | ||
], | ||
"author": "David Merfield", | ||
"license": "CC0", | ||
"bugs": {"url": "https://github.com/davidmerfield/randomColor/issues"}, | ||
"homepage": "https://randomcolor.llllll.li/", | ||
"spm": {"main": "randomColor.js"}, | ||
"devDependencies": { | ||
"cheerio": "^0.19.0", | ||
"highlight": "^0.2.3", | ||
"highlight.js": "^8.7.0", | ||
"html-minifier": "^0.7.2" | ||
} | ||
"bugs": { | ||
"url": "https://github.com/davidmerfield/randomColor/issues" | ||
}, | ||
"homepage": "https://randomcolor.lllllllllllllllll.com/", | ||
"spm": { | ||
"main": "randomColor.js" | ||
}, | ||
"devDependencies": {}, | ||
"dependencies": {} | ||
} |
@@ -38,2 +38,5 @@ // randomColor by David Merfield under the CC0 license | ||
// check if a range is taken | ||
var colorRanges = []; | ||
var randomColor = function (options) { | ||
@@ -68,3 +71,6 @@ | ||
colors = []; | ||
// Value false at index i means the range i is not taken yet. | ||
for (var i = 0; i < options.count; i++) { | ||
colorRanges.push(false) | ||
} | ||
options.count = null; | ||
@@ -100,13 +106,43 @@ | ||
function pickHue (options) { | ||
function pickHue(options) { | ||
if (colorRanges.length > 0) { | ||
var hueRange = getRealHueRange(options.hue) | ||
var hueRange = getHueRange(options.hue), | ||
hue = randomWithin(hueRange); | ||
var hue = randomWithin(hueRange) | ||
// Instead of storing red as two seperate ranges, | ||
// we group them, using negative numbers | ||
if (hue < 0) {hue = 360 + hue;} | ||
//Each of colorRanges.length ranges has a length equal approximatelly one step | ||
var step = (hueRange[1] - hueRange[0]) / colorRanges.length | ||
return hue; | ||
var j = parseInt((hue - hueRange[0]) / step) | ||
//Check if the range j is taken | ||
if (colorRanges[j] === true) { | ||
j = (j + 2) % colorRanges.length | ||
} | ||
else { | ||
colorRanges[j] = true | ||
} | ||
var min = (hueRange[0] + j * step) % 359, | ||
max = (hueRange[0] + (j + 1) * step) % 359; | ||
hueRange = [min, max] | ||
hue = randomWithin(hueRange) | ||
if (hue < 0) {hue = 360 + hue;} | ||
return hue | ||
} | ||
else { | ||
var hueRange = getHueRange(options.hue) | ||
hue = randomWithin(hueRange); | ||
// Instead of storing red as two seperate ranges, | ||
// we group them, using negative numbers | ||
if (hue < 0) { | ||
hue = 360 + hue; | ||
} | ||
return hue; | ||
} | ||
} | ||
@@ -284,3 +320,8 @@ | ||
if (seed === null) { | ||
return Math.floor(range[0] + Math.random()*(range[1] + 1 - range[0])); | ||
//generate random evenly destinct number from : https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ | ||
var golden_ratio = 0.618033988749895 | ||
var r=Math.random() | ||
r += golden_ratio | ||
r %= 1 | ||
return Math.floor(range[0] + r*(range[1] + 1 - range[0])); | ||
} else { | ||
@@ -293,3 +334,3 @@ //Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | ||
return Math.floor(min + rnd * (max - min)); | ||
} | ||
} | ||
} | ||
@@ -457,3 +498,28 @@ | ||
// get The range of given hue when options.count!=0 | ||
function getRealHueRange(colorHue) | ||
{ if (!isNaN(colorHue)) { | ||
var number = parseInt(colorHue); | ||
if (number < 360 && number > 0) { | ||
return getColorInfo(colorHue).hueRange | ||
} | ||
} | ||
else if (typeof colorHue === 'string') { | ||
if (colorDictionary[colorHue]) { | ||
var color = colorDictionary[colorHue]; | ||
if (color.hueRange) { | ||
return color.hueRange | ||
} | ||
} else if (colorHue.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) { | ||
var hue = HexToHSB(colorHue)[0] | ||
return getColorInfo(hue).hueRange | ||
} | ||
} | ||
return [0,360] | ||
} | ||
return randomColor; | ||
})); |
@@ -1,6 +0,6 @@ | ||
# [Random Color](http://llllll.li/randomColor) | ||
# [Random Color](https://randomcolor.lllllllllllllllll.com) | ||
A tiny script for generating attractive random colors. See the demo for [an explanation](http://llllll.li/randomColor/) and [some samples](http://llllll.li/randomColor/). randomColor has been ported to [C#](https://github.com/nathanpjones/randomColorSharped), [C++](https://github.com/xuboying/randomcolor-cpp), [Go](https://github.com/hansrodtang/randomcolor), [PHP](https://github.com/mistic100/RandomColor.php), [Python](https://github.com/kevinwuhoo/randomcolor-py), [Swift](https://github.com/onevcat/RandomColorSwift), [Objective-C](https://github.com/yageek/randomColor), [Java](https://github.com/lzyzsd/AndroidRandomColor) and [R](https://github.com/ronammar/randomcoloR). | ||
A tiny script for generating attractive random colors. See the demo for [an explanation](https://randomcolor.lllllllllllllllll.com) and [some samples](https://randomcolor.lllllllllllllllll.com). randomColor has been ported to [C#](https://github.com/nathanpjones/randomColorSharped), [C++](https://github.com/xuboying/randomcolor-cpp), [Go](https://github.com/hansrodtang/randomcolor), [Haskell](http://hackage.haskell.org/package/palette-0.3/docs/Data-Colour-Palette-RandomColor.html), [PHP](https://github.com/mistic100/RandomColor.php), [Python](https://github.com/kevinwuhoo/randomcolor-py), [Swift](https://github.com/onevcat/RandomColorSwift), [Perl6](https://github.com/Xliff/p6-RandomColor), [Objective-C](https://github.com/yageek/randomColor), [Java](https://github.com/lzyzsd/AndroidRandomColor), [R](https://github.com/ronammar/randomcoloR) and [Rust](https://github.com/elementh/random_color). | ||
[![Demo](http://i.imgur.com/lOLCqvu.gif)](http://llllll.li/randomColor) | ||
[![Demo](http://i.imgur.com/lOLCqvu.gif)](https://randomcolor.lllllllllllllllll.com) | ||
@@ -95,16 +95,24 @@ To use randomColor **in the browser**, download the [latest minified version of randomColor](http://cdnjs.com/libraries/randomcolor) and include it on your page. Then call the script: | ||
0. use this on the demo | ||
1. Use this on the demo | ||
http://jsfiddle.net/dpLp318f/ | ||
https://www.vis4.net/blog/posts/avoid-equidistant-hsv-colors/ | ||
https://www.vis4.net/blog/posts/mastering-multi-hued-color-scales/ | ||
1. When returning an array of multiple colors, try to make each color as distinct as possible. Make sure each color is distinct to its neighbours. | ||
2. Improve attractive dark color generation, currently they're a touch murky. | ||
3. Improve the color dictionary | ||
2. When returning an array of multiple colors, try to make each color as distinct as possible. Make sure each color is distinct to its neighbours. | ||
3. Improve attractive dark color generation, currently they're a touch murky. | ||
4. Improve the color dictionary | ||
- definition of hue values and attractive luminosity bounds | ||
- think about how to store hue aliases (e.g. fuschia) or subranges (e.g teal) | ||
- think about making a little point and click tool for defining your own luminosity bounds and customizing the color dictionary | ||
4. Think about how to return seeds. | ||
5. Think about adding feature to return complementary & contrasting colors, as well as color triads, tetrads etc. Other libraries might already do this better though. | ||
6. Think about adding a scheme options which would return a dominant color, as well as secondary, tertiary color and primary and secondary text colors. This might be a bad idea. | ||
7. Add a nice visualization of the 'attractive color space' to the demo https://www.youtube.com/watch?v=x0-qoXOCOow | ||
7. Add a feature to return random colors close to a provided hex | ||
5. Think about how to return seeds. | ||
6. Think about adding feature to return complementary & contrasting colors, as well as color triads, tetrads etc. Other libraries might already do this better though. | ||
7. Think about adding a scheme options which would return a dominant color, as well as secondary, tertiary color and primary and secondary text colors. This might be a bad idea. | ||
8. Add a nice visualization of the 'attractive color space' to the demo https://www.youtube.com/watch?v=x0-qoXOCOow | ||
9. Add a feature to return random colors close to a provided hex | ||
## In use | ||
* [The Daily Show](http://maketrumptweetseightagain.com/) used it to make an extension which [converts Trump's tweets into a child's scribble](https://twitter.com/riseuphes/status/929579600354693120). | ||
* [Initial.js](https://github.com/judesfernando/initial.js) used it to generate Gmail-style avatars. | ||
* [ng2-Logger](https://github.com/darekf77/ng2-logger) used it to make logs a little more colorful. | ||
Did you use randomColor.js for something? [Tell me about it](https://lllllllllllllllll.com). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
0
0
100
118
0
1
25229
4
387