This repository has been archived by the owner on Oct 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
154 lines (137 loc) · 7.19 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<title>golden-colors</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<style type="text/css">
h1 {
margin-top: 10px;
}
.buttons-block {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="buttons-block">
<a class="btn btn-default btn-xs" href="https://github.com/Alex7Kom/golden-colors" role="button">View on Github</a>
<a class="btn btn-danger btn-xs" href="https://www.npmjs.com/package/golden-colors" role="button">View on npm</a>
</div>
<h1 id="golden-colors">golden-colors</h1>
<p>Random color generation for JavaScript and Node.js based on <a href="http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/">How To Generate Random Colors Programmatically</a> by <strong>Martin Ankerl</strong>. Colors generated using Golden ratio conjugate can be used as background colors for easily readable labels, buttons, etc.</p>
<h2 id="installation">Installation</h2>
<p>Download <a href="https://github.com/Alex7Kom/golden-colors/releases/latest">the latest version</a> from Github or use npm or Bower:</p>
<pre><code>npm install golden-colors
</code></pre><p>Then just include <code>dist/golden-colors.js</code> or <code>dist/golden-colors.min.js</code> in your html. AMD-version of the library that also supports Browserify also available as <code>dist/golden-colors-amd.js</code>/<code>dist/golden-colors-amd.min.js</code>.</p>
<p>and require it in your code:</p>
<pre><code class="lang-js">var goldenColors = require('golden-colors');
</code></pre>
<h2 id="api">API</h2>
<h3 id="goldencolors">goldenColors</h3>
<p>There are three functions for color generation. All three functions return an instance of <a href="#webcolor">WebColor</a>.</p>
<h4 id="gethsvgolden-s-v-">getHsvGolden(s, v)</h4>
<p>Random color in <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">HSV</a> system with random value for hue set at startup and distributed using <a href="https://en.wikipedia.org/wiki/Golden_ratio#Golden_ratio_conjugate">Golden ratio conjugate</a> with specified saturation and value.</p>
<h4 id="gethsvsimple-s-v-">getHsvSimple(s, v)</h4>
<p>Random color in <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">HSV</a> system with random values for hue with specified saturation and value.</p>
<h4 id="getnaive-">getNaive()</h4>
<p>Just random values for R, G, B.</p>
<h3 id="webcolor">WebColor</h3>
<p>An object with R, G, and B values that can be converted into CSS2-compatible string.</p>
<h4 id="torgb-">toRgb()</h4>
<p>Returns an Array of <code>[r, g, b]</code> with decimal values.</p>
<h4 id="torgbstring-">toRgbString()</h4>
<p>Returns a String of <code>rgb(r, g, b)</code> with decimal values.</p>
<h4 id="tohexstring-">toHexString()</h4>
<h4 id="tostring-">toString()</h4>
<h4 id="tojson-">toJSON()</h4>
<p>Returns a String of <code>#rgb</code> with hexadecimal values.</p>
<h2 id="license">License</h2>
<p>The MIT License (MIT)</p>
<p>Copyright (c) 2014-2015 Alexey Komarov <a href="mailto:alex7kom@gmail.com">alex7kom@gmail.com</a></p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
<h2 id="examples">Examples</h2>
<p><strong>getHsvGolden(s, v)</strong></p>
<p>
<pre><code class="javascript">goldenColors.getHsvGolden(0.5, 0.95)</code></pre>
</p>
<div class="progress" id="golden_bar_5_95"></div>
<p>
<pre><code class="javascript">goldenColors.getHsvGolden(0.99, 0.99)</code></pre>
</p>
<div class="progress" id="golden_bar_99_99"></div>
<p>
<pre><code class="javascript">goldenColors.getHsvGolden(0.25, 0.8)</code></pre>
</p>
<div class="progress" id="golden_bar_25_8"></div>
<p>
<pre><code class="javascript">goldenColors.getHsvGolden(0.3, 0.99)</code></pre>
</p>
<div class="progress" id="golden_bar_3_99"></div>
<p><strong>getHsvSimple(s, v)</strong></p>
<p>
<pre><code class="javascript">goldenColors.getHsvSimple(0.5, 0.95)</code></pre>
</p>
<div class="progress" id="simple_bar"></div>
<p><strong>getNaive()</strong></p>
<p>
<pre><code class="javascript">goldenColors.getNaive()</code></pre>
</p>
<div class="progress" id="naive_bar"></div>
</div>
<div class="col-md-3"></div>
</div>
</div>
<script type="text/javascript" src="dist/golden-colors-amd.js"></script>
<script type="text/javascript">
(function() {
var abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var stripWidth = 100 / abc.length;
function createColorStrip (color, width, letter) {
var elem = document.createElement('div');
elem.className = 'progress-bar';
elem.style.cssText = 'width: ' + width + '%; color: #000; background-color: ' + color;
console.log(color);
console.log(letter);
elem.innerText = letter;
return elem;
}
abc.forEach(function(letter) {
naive_bar.appendChild(createColorStrip(goldenColors.getNaive(), stripWidth, letter));
simple_bar.appendChild(createColorStrip(goldenColors.getHsvSimple(0.5, 0.95), stripWidth, letter));
});
abc.forEach(function(letter) {
golden_bar_99_99.appendChild(createColorStrip(goldenColors.getHsvGolden(0.99, 0.99), stripWidth, letter));
});
abc.forEach(function(letter) {
golden_bar_25_8.appendChild(createColorStrip(goldenColors.getHsvGolden(0.25, 0.8), stripWidth, letter));
});
abc.forEach(function(letter) {
golden_bar_5_95.appendChild(createColorStrip(goldenColors.getHsvGolden(0.5, 0.95), stripWidth, letter));
});
abc.forEach(function(letter) {
golden_bar_3_99.appendChild(createColorStrip(goldenColors.getHsvGolden(0.3, 0.99), stripWidth, letter));
});
})();
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>