|
1 | 1 | # TinyColor |
2 | 2 |
|
3 | | -## JavaScript color parsing |
| 3 | +## JavaScript color tooling |
4 | 4 |
|
5 | | -Fast, small color manipulation and conversion for JavaScript. TinyColor is allows many forms of input, while providing color conversions and other color utility functions. It has no dependencies. |
| 5 | +TinyColor is a small, fast library for color manipulation and conversion in JavaScript. It allows many forms of input, while providing color conversions and other color utility functions. It has no dependencies. |
6 | 6 |
|
7 | 7 | [](https://travis-ci.org/bgrins/TinyColor) |
8 | 8 |
|
9 | 9 | ## Including in a browser |
10 | 10 |
|
| 11 | +Download [tinycolor.js](https://raw.githubusercontent.com/bgrins/TinyColor/master/tinycolor.js) or install it with bower: |
| 12 | + |
| 13 | + bower install tinycolor |
| 14 | + |
| 15 | +Then just include it in the page in a `script` tag: |
| 16 | + |
11 | 17 | <script type='text/javascript' src='tinycolor.js'></script> |
12 | 18 | <script type='text/javascript'> |
13 | 19 | var color = tinycolor("red"); |
@@ -238,33 +244,118 @@ Print to a string, depending on the input format. You can also override this by |
238 | 244 | color2.setAlpha(.5); |
239 | 245 | color2.toString(); // "rgba(255, 0, 0, 0.5)" |
240 | 246 |
|
241 | | -## Color Utilities |
| 247 | +### Color Modification |
242 | 248 |
|
243 | | - tinycolor.equals(color1, color2) |
| 249 | +These methods manipulate the current color, and return it for chaining. For instance: |
244 | 250 |
|
245 | | -### Color Modification |
| 251 | + tinycolor("red").lighten().desaturate().toHexString() // "#f53d3d" |
246 | 252 |
|
247 | | -Modification functions may take an `amount` variable from 0 - 100, indicating how much the effect should be applied. |
| 253 | +### lighten |
248 | 254 |
|
249 | | - tinycolor.lighten(color, amount = 10) |
250 | | - tinycolor.brighten(color, amount = 10) |
251 | | - tinycolor.darken(color, amount = 10) |
252 | | - tinycolor.desaturate(color, amount = 10) |
253 | | - tinycolor.saturate(color, amount = 10) |
254 | | - tinycolor.greyscale(color) |
255 | | - tinycolor.spin(color, amount) |
256 | | - tinycolor.mix(color1, color2, amount = 50) |
| 255 | +`lighten: function(amount = 10) -> TinyColor`. Lighten the color a given amount, from 0 to 100. Providing 100 will always return white. |
| 256 | + |
| 257 | + tinycolor("#f00").lighten().toString(); // "#ff3333" |
| 258 | + tinycolor("#f00").lighten(100).toString(); // "#ffffff" |
| 259 | + |
| 260 | +### brighten |
| 261 | + |
| 262 | +`brighten: function(amount = 10) -> TinyColor`. Brighten the color a given amount, from 0 to 100. |
| 263 | + |
| 264 | + tinycolor("#f00").brighten().toString(); // "#ff1919" |
| 265 | + |
| 266 | +### darken |
| 267 | + |
| 268 | +`darken: function(amount = 10) -> TinyColor`. Darken the color a given amount, from 0 to 100. Providing 100 will always return black. |
| 269 | + |
| 270 | + tinycolor("#f00").darken().toString(); // "#cc0000" |
| 271 | + tinycolor("#f00").darken(100).toString(); // "#000000" |
| 272 | + |
| 273 | +### desaturate |
| 274 | + |
| 275 | +`desaturate: function(amount = 10) -> TinyColor`. Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling `greyscale`. |
| 276 | + |
| 277 | + tinycolor("#f00").desaturate().toString(); // "#f20d0d" |
| 278 | + tinycolor("#f00").desaturate(100).toString(); // "#808080" |
| 279 | + |
| 280 | +### saturate |
| 281 | + |
| 282 | +`saturate: function(amount = 10) -> TinyColor`. Saturate the color a given amount, from 0 to 100. |
| 283 | + |
| 284 | + tinycolor("hsl(0, 10%, 50%)").saturate().toString(); // "hsl(0, 20%, 50%)" |
| 285 | + |
| 286 | +### greyscale |
| 287 | + |
| 288 | +`greyscale: function() -> TinyColor`. Completely desaturates a color into greyscale. Same as calling `desaturate(100)`. |
| 289 | + |
| 290 | + tinycolor("#f00").greyscale().toString(); // "#808080" |
| 291 | + |
| 292 | +### spin |
| 293 | + |
| 294 | +`spin: function(amount = 0) -> TinyColor`. Spin the hue a given amount, from -360 to 360. Calling with 0, 360, or -360 will do nothing (since it sets the hue back to what it was before). |
| 295 | + |
| 296 | + tinycolor("#f00").spin(180).toString(); // "#00ffff" |
| 297 | + tinycolor("#f00").spin(-90).toString(); // "#7f00ff" |
| 298 | + tinycolor("#f00").spin(90).toString(); // "#80ff00" |
| 299 | + |
| 300 | + // spin(0) and spin(360) do nothing |
| 301 | + tinycolor("#f00").spin(0).toString(); // "#ff0000" |
| 302 | + tinycolor("#f00").spin(360).toString(); // "#ff0000" |
257 | 303 |
|
258 | 304 | ### Color Combinations |
259 | 305 |
|
260 | | -Combination functions return an Array of TinyColor objects. |
| 306 | +Combination functions return an array of TinyColor objects unless otherwise noted. |
261 | 307 |
|
262 | | - tinycolor.analogous(color, results = 6, slices = 30) |
263 | | - tinycolor.complement(color) |
264 | | - tinycolor.monochromatic(color, results = 6) |
265 | | - tinycolor.splitcomplement(color) |
266 | | - tinycolor.triad(color) |
267 | | - tinycolor.tetrad(color) |
| 308 | +### analogous |
| 309 | + |
| 310 | +`analogous: function(, results = 6, slices = 30) -> array<TinyColor>`. |
| 311 | + |
| 312 | + var colors = tinycolor("#f00").analogous(); |
| 313 | + |
| 314 | + colors.map(function(t) { return t.toHexString(); }); // [ "#ff0000", "#ff0066", "#ff0033", "#ff0000", "#ff3300", "#ff6600" ] |
| 315 | + |
| 316 | +### monochromatic |
| 317 | + |
| 318 | +`monochromatic: function(, results = 6) -> array<TinyColor>`. |
| 319 | + |
| 320 | + var colors = tinycolor("#f00").monochromatic(); |
| 321 | + |
| 322 | + colors.map(function(t) { return t.toHexString(); }); // [ "#ff0000", "#2a0000", "#550000", "#800000", "#aa0000", "#d40000" ] |
| 323 | + |
| 324 | +### splitcomplement |
| 325 | + |
| 326 | +`splitcomplement: function() -> array<TinyColor>`. |
| 327 | + |
| 328 | + var colors = tinycolor("#f00").splitcomplement(); |
| 329 | + |
| 330 | + colors.map(function(t) { return t.toHexString(); }); // [ "#ff0000", "#ccff00", "#0066ff" ] |
| 331 | + |
| 332 | +### triad |
| 333 | + |
| 334 | +`triad: function() -> array<TinyColor>`. |
| 335 | + |
| 336 | + var colors = tinycolor("#f00").triad(); |
| 337 | + |
| 338 | + colors.map(function(t) { return t.toHexString(); }); // [ "#ff0000", "#00ff00", "#0000ff" ] |
| 339 | + |
| 340 | +### tetrad |
| 341 | + |
| 342 | +`tetrad: function() -> array<TinyColor>`. |
| 343 | + |
| 344 | + var colors = tinycolor("#f00").tetrad(); |
| 345 | + |
| 346 | + colors.map(function(t) { return t.toHexString(); }); // [ "#ff0000", "#80ff00", "#00ffff", "#7f00ff" ] |
| 347 | + |
| 348 | + |
| 349 | +### complement |
| 350 | + |
| 351 | +`complement: function() -> TinyColor`. |
| 352 | + |
| 353 | + tinycolor("#f00").complement().toHexString(); // "#00ffff" |
| 354 | + |
| 355 | +## Color Utilities |
| 356 | + |
| 357 | + tinycolor.equals(color1, color2) |
| 358 | + tinycolor.mix(color1, color2, amount = 50) |
268 | 359 |
|
269 | 360 | ### Readability |
270 | 361 |
|
|
0 commit comments