├── .gitignore ├── .npmignore ├── Cakefile ├── LICENSE ├── README.md ├── TODO.md ├── index.d.ts ├── index.html ├── lib ├── color-scheme.js ├── color-scheme.js.map └── color-scheme.min.js ├── old_index.html ├── package.json ├── params.json ├── src └── lib │ └── color-scheme.coffee ├── test.coffee ├── test.js └── test ├── mutablecolor.coffee ├── test.coffee └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | .idea 17 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | src 3 | node_modules -------------------------------------------------------------------------------- /Cakefile: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | sys = require 'sys' 3 | path = require 'path' 4 | {exec} = require 'child_process' 5 | UglifyJS = require 'uglify-js' 6 | 7 | task 'compile', 'Compile coffee-script to JavaScript', -> 8 | compile() 9 | 10 | task 'test', 'Test this module', -> 11 | test() 12 | 13 | task 'build', 'Build this module', -> 14 | build() 15 | 16 | task 'minify', 'Minify the compiled javascript source', -> 17 | minify() 18 | 19 | compile = (callback) -> 20 | console.log "Compiling..." 21 | 22 | # Create the lib directory if it doesn't exist 23 | if !fs.existsSync("lib") 24 | fs.mkdirSync "lib" 25 | 26 | # Compile the library 27 | child = exec '"node_modules/.bin/coffee" -m -o lib ./src/lib/color-scheme.coffee', (err, stdout, stderr) -> 28 | if err? 29 | throw err 30 | else 31 | callback() if callback? 32 | 33 | # Redirect the child process' output to our stdout 34 | child.stdout.on 'data', (data) -> sys.print data 35 | child.stderr.on 'data', (data) -> sys.print data 36 | 37 | test = (callback) -> 38 | console.log "Testing..." 39 | 40 | child = exec '"node_modules/.bin/mocha" --reporter list --compilers coffee:coffee-script/register test', (err, stdout, stderr) -> 41 | # console.log stdout 42 | # console.log stderr 43 | 44 | if err? 45 | process.exit() 46 | else 47 | callback() if callback? 48 | 49 | # Redirect the child process' output to our stdout 50 | child.stdout.on 'data', (data) -> sys.print data 51 | child.stderr.on 'data', (data) -> sys.print data 52 | 53 | minify = (callback) -> 54 | console.log "Minifying..." 55 | 56 | compiled = UglifyJS.minify('lib/color-scheme.js') 57 | fs.writeFileSync 'lib/color-scheme.min.js', compiled.code.toString() 58 | 59 | callback() if callback? 60 | 61 | # Run all the tasks one after the other! 62 | build = (callback) -> 63 | test () -> 64 | compile () -> 65 | minify () -> 66 | console.log "Done!" 67 | callback() if callback? -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Brian Hann 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # color-scheme.js 2 | 3 | Generate pleasant color schemes (sets of colors). 4 | 5 | This library is based on the perl module [Color::Scheme](http://search.cpan.org/~rjbs/Color-Scheme-1.04/lib/Color/Scheme.pm), which is in turn based on the [Color Scheme Designer website](http://colorschemedesigner.com/). 6 | 7 | Check out [how it works](http://c0bra.github.com/color-scheme-js/). 8 | 9 | Get the [minified file](https://raw.github.com/c0bra/color-scheme-js/master/lib/color-scheme.min.js) (8kb). 10 | 11 | Or for some reason, you could use the [full file](https://raw.github.com/c0bra/color-scheme-js/master/lib/color-scheme.js) (18kb). 12 | 13 | ## Table of Contents 14 | 15 | - [Description](#description) 16 | - [Usage](#usage) 17 | - [Schemes](#schemes) 18 | - [mono](#mono-monochromatic) 19 | - [contrast](#contrast) 20 | - [triade](#triade) 21 | - [tetrade](#tetrade) 22 | - [analogic](#analogic) 23 | - [Variations](#variations) 24 | - [pastel](#pastel) 25 | - [soft](#soft) 26 | - [light](#light) 27 | - [hard](#hard) 28 | - [pale](#pale) 29 | - [Methods](#methods) 30 | 31 | ## Description 32 | 33 | This module is a JavaScript implementation of the Perl implementation of Color Schemes 34 | 2 ([http://wellstyled.com/tools/colorscheme2](http://wellstyled.com/tools/colorscheme2)), a color scheme generator. 35 | Start by visitng the Color Schemes 2 web site and playing with the colors. 36 | When you want to generate those schemes on the fly, begin using this modoule. 37 | The descriptions herein don't make too much sense without actually seeing the 38 | colorful results. 39 | 40 | Henceforth, paragraphs in quotes denote documentation copied from Color Schemes 2. 41 | 42 | *"Important note: **This tool doesn't use the standard HSV or HSB model** (the 43 | same HSV/HSB values ie. in Photoshop describe different colors!). The color 44 | wheel used here differs from the RGB spectre used on computer screens, it's 45 | more in accordance with the classical color theory. This is also why some 46 | colors (especially shades of blue) make less bright shades than the basic 47 | colors of the RGB-model. In plus, the RGB-model uses red-green-blue as primary 48 | colors, but the red-yellow-blue combination is used here. This deformation also 49 | causes incompatibility in color conversions from RGB-values. Therefore, the RGB 50 | input (eg. the HTML hex values like #F854A9) is not exact, the conversion is 51 | rough and sometimes may produce slightly different color."* 52 | 53 | ## Usage 54 | 55 | ### In node.js 56 | 57 | Gotta install it first: 58 | 59 | ``` 60 | npm install color-scheme 61 | ``` 62 | 63 | ```javascript 64 | var ColorScheme = require('color-scheme'); 65 | 66 | var scheme = new ColorScheme; 67 | scheme.from_hue(21) // Start the scheme 68 | .scheme('triade') // Use the 'triade' scheme, that is, colors 69 | // selected from 3 points equidistant around 70 | // the color wheel. 71 | .variation('soft'); // Use the 'soft' color variation 72 | 73 | var colors = scheme.colors(); 74 | 75 | /* 76 | colors = [ "e69373", "805240", "e6d5cf", "bf5830" , 77 | "77d36a", "488040", "d2e6cf", "43bf30" , 78 | "557aaa", "405c80", "cfd9e6", "306ebf" ] 79 | */ 80 | ``` 81 | 82 | ### In the browser 83 | 84 | ```html 85 | 86 | 87 | 184 | 185 | 186 | 187 | 372 | 373 | -------------------------------------------------------------------------------- /lib/color-scheme.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.12.7 2 | (function() { 3 | var ColorScheme, 4 | slice = [].slice; 5 | 6 | ColorScheme = (function() { 7 | var clone, l, len, ref, typeIsArray, word; 8 | 9 | typeIsArray = Array.isArray || function(value) { 10 | return {}.toString.call(value) === '[object Array]'; 11 | }; 12 | 13 | ColorScheme.SCHEMES = {}; 14 | 15 | ref = "mono monochromatic contrast triade tetrade analogic".split(/\s+/); 16 | for (l = 0, len = ref.length; l < len; l++) { 17 | word = ref[l]; 18 | ColorScheme.SCHEMES[word] = true; 19 | } 20 | 21 | ColorScheme.PRESETS = { 22 | "default": [-1, -1, 1, -0.7, 0.25, 1, 0.5, 1], 23 | pastel: [0.5, -0.9, 0.5, 0.5, 0.1, 0.9, 0.75, 0.75], 24 | soft: [0.3, -0.8, 0.3, 0.5, 0.1, 0.9, 0.5, 0.75], 25 | light: [0.25, 1, 0.5, 0.75, 0.1, 1, 0.5, 1], 26 | hard: [1, -1, 1, -0.6, 0.1, 1, 0.6, 1], 27 | pale: [0.1, -0.85, 0.1, 0.5, 0.1, 1, 0.1, 0.75] 28 | }; 29 | 30 | ColorScheme.COLOR_WHEEL = { 31 | 0: [255, 0, 0, 100], 32 | 15: [255, 51, 0, 100], 33 | 30: [255, 102, 0, 100], 34 | 45: [255, 128, 0, 100], 35 | 60: [255, 153, 0, 100], 36 | 75: [255, 178, 0, 100], 37 | 90: [255, 204, 0, 100], 38 | 105: [255, 229, 0, 100], 39 | 120: [255, 255, 0, 100], 40 | 135: [204, 255, 0, 100], 41 | 150: [153, 255, 0, 100], 42 | 165: [51, 255, 0, 100], 43 | 180: [0, 204, 0, 80], 44 | 195: [0, 178, 102, 70], 45 | 210: [0, 153, 153, 60], 46 | 225: [0, 102, 178, 70], 47 | 240: [0, 51, 204, 80], 48 | 255: [25, 25, 178, 70], 49 | 270: [51, 0, 153, 60], 50 | 285: [64, 0, 153, 60], 51 | 300: [102, 0, 153, 60], 52 | 315: [153, 0, 153, 60], 53 | 330: [204, 0, 153, 80], 54 | 345: [229, 0, 102, 90] 55 | }; 56 | 57 | function ColorScheme() { 58 | var colors, m; 59 | colors = []; 60 | for (m = 1; m <= 4; m++) { 61 | colors.push(new ColorScheme.mutablecolor(60)); 62 | } 63 | this.col = colors; 64 | this._scheme = 'mono'; 65 | this._distance = 0.5; 66 | this._web_safe = false; 67 | this._add_complement = false; 68 | } 69 | 70 | 71 | /* 72 | 73 | colors() 74 | 75 | Returns an array of 4, 8, 12 or 16 colors in RRGGBB hexidecimal notation 76 | (without a leading "#") depending on the color scheme and addComplement 77 | parameter. For each set of four, the first is usually the most saturated color, 78 | the second a darkened version, the third a pale version and fourth 79 | a less-pale version. 80 | 81 | For example: With a contrast scheme, "colors()" would return eight colors. 82 | Indexes 1 and 5 could be background colors, 2 and 6 could be foreground colors. 83 | 84 | Trust me, it's much better if you check out the Color Scheme web site, whose 85 | URL is listed in "Description" 86 | */ 87 | 88 | ColorScheme.prototype.colors = function() { 89 | var dispatch, h, i, j, m, n, output, ref1, used_colors; 90 | used_colors = 1; 91 | h = this.col[0].get_hue(); 92 | dispatch = { 93 | mono: (function(_this) { 94 | return function() {}; 95 | })(this), 96 | contrast: (function(_this) { 97 | return function() { 98 | used_colors = 2; 99 | _this.col[1].set_hue(h); 100 | return _this.col[1].rotate(180); 101 | }; 102 | })(this), 103 | triade: (function(_this) { 104 | return function() { 105 | var dif; 106 | used_colors = 3; 107 | dif = 60 * _this._distance; 108 | _this.col[1].set_hue(h); 109 | _this.col[1].rotate(180 - dif); 110 | _this.col[2].set_hue(h); 111 | return _this.col[2].rotate(180 + dif); 112 | }; 113 | })(this), 114 | tetrade: (function(_this) { 115 | return function() { 116 | var dif; 117 | used_colors = 4; 118 | dif = 90 * _this._distance; 119 | _this.col[1].set_hue(h); 120 | _this.col[1].rotate(180); 121 | _this.col[2].set_hue(h); 122 | _this.col[2].rotate(180 + dif); 123 | _this.col[3].set_hue(h); 124 | return _this.col[3].rotate(dif); 125 | }; 126 | })(this), 127 | analogic: (function(_this) { 128 | return function() { 129 | var dif; 130 | used_colors = _this._add_complement ? 4 : 3; 131 | dif = 60 * _this._distance; 132 | _this.col[1].set_hue(h); 133 | _this.col[1].rotate(dif); 134 | _this.col[2].set_hue(h); 135 | _this.col[2].rotate(360 - dif); 136 | _this.col[3].set_hue(h); 137 | return _this.col[3].rotate(180); 138 | }; 139 | })(this) 140 | }; 141 | dispatch['monochromatic'] = dispatch['mono']; 142 | if (dispatch[this._scheme] != null) { 143 | dispatch[this._scheme](); 144 | } else { 145 | throw "Unknown color scheme name: " + this._scheme; 146 | } 147 | output = []; 148 | for (i = m = 0, ref1 = used_colors - 1; 0 <= ref1 ? m <= ref1 : m >= ref1; i = 0 <= ref1 ? ++m : --m) { 149 | for (j = n = 0; n <= 3; j = ++n) { 150 | output[i * 4 + j] = this.col[i].get_hex(this._web_safe, j); 151 | } 152 | } 153 | return output; 154 | }; 155 | 156 | 157 | /* 158 | 159 | colorset() 160 | 161 | Returns a list of lists of the colors in groups of four. This method simply 162 | allows you to reference a color in the scheme by its group isntead of its 163 | absolute index in the list of colors. I am assuming that "colorset()" 164 | will make it easier to use this module with the templating systems that are 165 | out there. 166 | 167 | For example, if you were to follow the synopsis, say you wanted to retrieve 168 | the two darkest colors from the first two groups of the scheme, which is 169 | typically the second color in the group. You could retrieve them with 170 | "colors()" 171 | 172 | first_background = (scheme.colors())[1]; 173 | second_background = (scheme.colors())[5]; 174 | 175 | Or, with this method, 176 | 177 | first_background = (scheme.colorset())[0][1] 178 | second_background = (scheme.colorset())[1][1] 179 | */ 180 | 181 | ColorScheme.prototype.colorset = function() { 182 | var flat_colors, grouped_colors; 183 | flat_colors = clone(this.colors()); 184 | grouped_colors = []; 185 | while (flat_colors.length > 0) { 186 | grouped_colors.push(flat_colors.splice(0, 4)); 187 | } 188 | return grouped_colors; 189 | }; 190 | 191 | 192 | /* 193 | 194 | from_hue( degrees ) 195 | 196 | Sets the base color hue, where 'degrees' is an integer. (Values greater than 197 | 359 and less than 0 wrap back around the wheel.) 198 | 199 | The default base hue is 0, or bright red. 200 | */ 201 | 202 | ColorScheme.prototype.from_hue = function(h) { 203 | if (h == null) { 204 | throw "from_hue needs an argument"; 205 | } 206 | this.col[0].set_hue(h); 207 | return this; 208 | }; 209 | 210 | ColorScheme.prototype.rgb2ryb = function() { 211 | var blue, green, iN, maxgreen, maxyellow, red, rgb, white, yellow; 212 | rgb = 1 <= arguments.length ? slice.call(arguments, 0) : []; 213 | if ((rgb[0] != null) && typeIsArray(rgb[0])) { 214 | rgb = rgb[0]; 215 | } 216 | red = rgb[0], green = rgb[1], blue = rgb[2]; 217 | white = Math.min(red, green, blue); 218 | red -= white; 219 | green -= white; 220 | blue -= white; 221 | maxgreen = Math.max(red, green, blue); 222 | yellow = Math.min(red, green); 223 | red -= yellow; 224 | green -= yellow; 225 | if (blue > 0 && green > 0) { 226 | blue /= 2; 227 | green /= 2; 228 | } 229 | yellow += green; 230 | blue += green; 231 | maxyellow = Math.max(red, yellow, blue); 232 | if (maxyellow > 0) { 233 | iN = maxgreen / maxyellow; 234 | red *= iN; 235 | yellow *= iN; 236 | blue *= iN; 237 | } 238 | red += white; 239 | yellow += white; 240 | blue += white; 241 | return [Math.floor(red), Math.floor(yellow), Math.floor(blue)]; 242 | }; 243 | 244 | ColorScheme.prototype.rgb2hsv = function() { 245 | var b, d, g, h, max, min, r, rgb, s, v; 246 | rgb = 1 <= arguments.length ? slice.call(arguments, 0) : []; 247 | if ((rgb[0] != null) && typeIsArray(rgb[0])) { 248 | rgb = rgb[0]; 249 | } 250 | r = rgb[0], g = rgb[1], b = rgb[2]; 251 | r /= 255; 252 | g /= 255; 253 | b /= 255; 254 | min = Math.min.apply(Math, [r, g, b]); 255 | max = Math.max.apply(Math, [r, g, b]); 256 | d = max - min; 257 | v = max; 258 | s; 259 | if (d > 0) { 260 | s = d / max; 261 | } else { 262 | return [0, 0, v]; 263 | } 264 | h = (r === max ? (g - b) / d : (g === max ? 2 + (b - r) / d : 4 + (r - g) / d)); 265 | h *= 60; 266 | h %= 360; 267 | return [h, s, v]; 268 | }; 269 | 270 | ColorScheme.prototype.rgbToHsv = function() { 271 | var b, d, g, h, max, min, r, rgb, s, v; 272 | rgb = 1 <= arguments.length ? slice.call(arguments, 0) : []; 273 | if ((rgb[0] != null) && typeIsArray(rgb[0])) { 274 | rgb = rgb[0]; 275 | } 276 | r = rgb[0], g = rgb[1], b = rgb[2]; 277 | r /= 255; 278 | g /= 255; 279 | b /= 255; 280 | max = Math.max(r, g, b); 281 | min = Math.min(r, g, b); 282 | h = void 0; 283 | s = void 0; 284 | v = max; 285 | d = max - min; 286 | s = max === 0 ? 0 : d / max; 287 | if (max === min) { 288 | h = 0; 289 | } else { 290 | switch (max) { 291 | case r: 292 | h = (g - b) / d + (g < b ? 6 : 0); 293 | break; 294 | case g: 295 | h = (b - r) / d + 2; 296 | break; 297 | case b: 298 | h = (r - g) / d + 4; 299 | } 300 | h /= 6; 301 | } 302 | return [h, s, v]; 303 | }; 304 | 305 | 306 | /* 307 | 308 | from_hex( color ) 309 | 310 | Sets the base color to the given color, where 'color' is in the hexidecimal 311 | form RRGGBB. 'color' should not be preceded with a hash (#). 312 | 313 | The default base color is the equivalent of #ff0000, or bright red. 314 | */ 315 | 316 | ColorScheme.prototype.from_hex = function(hex) { 317 | var b, g, h, h0, h1, h2, hsv, i1, i2, num, r, ref1, ref2, rgbcap, s, v; 318 | if (hex == null) { 319 | throw "from_hex needs an argument"; 320 | } 321 | if (!/^([0-9A-F]{2}){3}$/im.test(hex)) { 322 | throw "from_hex(" + hex + ") - argument must be in the form of RRGGBB"; 323 | } 324 | rgbcap = /(..)(..)(..)/.exec(hex).slice(1, 4); 325 | ref1 = (function() { 326 | var len1, m, results; 327 | results = []; 328 | for (m = 0, len1 = rgbcap.length; m < len1; m++) { 329 | num = rgbcap[m]; 330 | results.push(parseInt(num, 16)); 331 | } 332 | return results; 333 | })(), r = ref1[0], g = ref1[1], b = ref1[2]; 334 | ref2 = this.rgb2ryb([r, g, b]), r = ref2[0], g = ref2[1], b = ref2[2]; 335 | hsv = this.rgbToHsv(r, g, b); 336 | h0 = hsv[0]; 337 | h1 = 0; 338 | h2 = 1000; 339 | i1 = null; 340 | i2 = null; 341 | h = null; 342 | s = null; 343 | v = null; 344 | h = hsv[0]; 345 | s = hsv[1]; 346 | v = hsv[2]; 347 | this.from_hue(h * 360); 348 | this._set_variant_preset([s, v, s, v * 0.7, s * 0.25, 1, s * 0.5, 1]); 349 | return this; 350 | }; 351 | 352 | 353 | /* 354 | 355 | add_complement( BOOLEAN ) 356 | 357 | If BOOLEAN is true, an extra set of colors will be produced using the 358 | complement of the selected color. 359 | 360 | This only works with the analogic color scheme. The default is false. 361 | */ 362 | 363 | ColorScheme.prototype.add_complement = function(b) { 364 | if (b == null) { 365 | throw "add_complement needs an argument"; 366 | } 367 | this._add_complement = b; 368 | return this; 369 | }; 370 | 371 | 372 | /* 373 | 374 | web_safe( BOOL ) 375 | 376 | Sets whether the colors returned by L<"colors()"> or L<"colorset()"> will be 377 | web-safe. 378 | 379 | The default is false. 380 | */ 381 | 382 | ColorScheme.prototype.web_safe = function(b) { 383 | if (b == null) { 384 | throw "web_safe needs an argument"; 385 | } 386 | this._web_safe = b; 387 | return this; 388 | }; 389 | 390 | 391 | /* 392 | 393 | distance( FLOAT ) 394 | 395 | 'FLOAT'> must be a value from 0 to 1. You might use this with the "triade" 396 | "tetrade" or "analogic" color schemes. 397 | 398 | The default is 0.5. 399 | */ 400 | 401 | ColorScheme.prototype.distance = function(d) { 402 | if (d == null) { 403 | throw "distance needs an argument"; 404 | } 405 | if (d < 0) { 406 | throw "distance(" + d + ") - argument must be >= 0"; 407 | } 408 | if (d > 1) { 409 | throw "distance(" + d + ") - argument must be <= 1"; 410 | } 411 | this._distance = d; 412 | return this; 413 | }; 414 | 415 | 416 | /* 417 | 418 | scheme( name ) 419 | 420 | 'name' must be a valid color scheme name. See "Color Schemes". The default 421 | is "mono" 422 | */ 423 | 424 | ColorScheme.prototype.scheme = function(name) { 425 | if (name == null) { 426 | return this._scheme; 427 | } else { 428 | if (ColorScheme.SCHEMES[name] == null) { 429 | throw "'" + name + "' isn't a valid scheme name"; 430 | } 431 | this._scheme = name; 432 | return this; 433 | } 434 | }; 435 | 436 | 437 | /* 438 | 439 | variation( name ) 440 | 441 | 'name' must be a valid color variation name. See "Color Variations" 442 | */ 443 | 444 | ColorScheme.prototype.variation = function(v) { 445 | if (v == null) { 446 | throw "variation needs an argument"; 447 | } 448 | if (ColorScheme.PRESETS[v] == null) { 449 | throw "'$v' isn't a valid variation name"; 450 | } 451 | this._set_variant_preset(ColorScheme.PRESETS[v]); 452 | return this; 453 | }; 454 | 455 | ColorScheme.prototype._set_variant_preset = function(p) { 456 | var i, m, results; 457 | results = []; 458 | for (i = m = 0; m <= 3; i = ++m) { 459 | results.push(this.col[i].set_variant_preset(p)); 460 | } 461 | return results; 462 | }; 463 | 464 | clone = function(obj) { 465 | var flags, key, newInstance; 466 | if ((obj == null) || typeof obj !== 'object') { 467 | return obj; 468 | } 469 | if (obj instanceof Date) { 470 | return new Date(obj.getTime()); 471 | } 472 | if (obj instanceof RegExp) { 473 | flags = ''; 474 | if (obj.global != null) { 475 | flags += 'g'; 476 | } 477 | if (obj.ignoreCase != null) { 478 | flags += 'i'; 479 | } 480 | if (obj.multiline != null) { 481 | flags += 'm'; 482 | } 483 | if (obj.sticky != null) { 484 | flags += 'y'; 485 | } 486 | return new RegExp(obj.source, flags); 487 | } 488 | newInstance = new obj.constructor(); 489 | for (key in obj) { 490 | newInstance[key] = clone(obj[key]); 491 | } 492 | return newInstance; 493 | }; 494 | 495 | ColorScheme.mutablecolor = (function() { 496 | mutablecolor.prototype.hue = 0; 497 | 498 | mutablecolor.prototype.saturation = []; 499 | 500 | mutablecolor.prototype.value = []; 501 | 502 | mutablecolor.prototype.base_red = 0; 503 | 504 | mutablecolor.prototype.base_green = 0; 505 | 506 | mutablecolor.prototype.base_saturation = 0; 507 | 508 | mutablecolor.prototype.base_value = 0; 509 | 510 | function mutablecolor(hue) { 511 | if (hue == null) { 512 | throw "No hue specified"; 513 | } 514 | this.saturation = []; 515 | this.value = []; 516 | this.base_red = 0; 517 | this.base_green = 0; 518 | this.base_blue = 0; 519 | this.base_saturation = 0; 520 | this.base_value = 0; 521 | this.set_hue(hue); 522 | this.set_variant_preset(ColorScheme.PRESETS['default']); 523 | } 524 | 525 | mutablecolor.prototype.get_hue = function() { 526 | return this.hue; 527 | }; 528 | 529 | mutablecolor.prototype.set_hue = function(h) { 530 | var avrg, color, colorset1, colorset2, d, derivative1, derivative2, en, i, k; 531 | avrg = function(a, b, k) { 532 | return a + Math.round((b - a) * k); 533 | }; 534 | this.hue = Math.round(h % 360); 535 | d = this.hue % 15 + (this.hue - Math.floor(this.hue)); 536 | k = d / 15; 537 | derivative1 = this.hue - Math.floor(d); 538 | derivative2 = (derivative1 + 15) % 360; 539 | if (derivative1 === 360) { 540 | derivative1 = 0; 541 | } 542 | if (derivative2 === 360) { 543 | derivative2 = 0; 544 | } 545 | colorset1 = ColorScheme.COLOR_WHEEL[derivative1]; 546 | colorset2 = ColorScheme.COLOR_WHEEL[derivative2]; 547 | en = { 548 | red: 0, 549 | green: 1, 550 | blue: 2, 551 | value: 3 552 | }; 553 | for (color in en) { 554 | i = en[color]; 555 | this["base_" + color] = avrg(colorset1[i], colorset2[i], k); 556 | } 557 | this.base_saturation = avrg(100, 100, k) / 100; 558 | return this.base_value /= 100; 559 | }; 560 | 561 | mutablecolor.prototype.rotate = function(angle) { 562 | var newhue; 563 | newhue = (this.hue + angle) % 360; 564 | return this.set_hue(newhue); 565 | }; 566 | 567 | mutablecolor.prototype.get_saturation = function(variation) { 568 | var s, x; 569 | x = this.saturation[variation]; 570 | s = x < 0 ? -x * this.base_saturation : x; 571 | if (s > 1) { 572 | s = 1; 573 | } 574 | if (s < 0) { 575 | s = 0; 576 | } 577 | return s; 578 | }; 579 | 580 | mutablecolor.prototype.get_value = function(variation) { 581 | var v, x; 582 | x = this.value[variation]; 583 | v = x < 0 ? -x * this.base_value : x; 584 | if (v > 1) { 585 | v = 1; 586 | } 587 | if (v < 0) { 588 | v = 0; 589 | } 590 | return v; 591 | }; 592 | 593 | mutablecolor.prototype.set_variant = function(variation, s, v) { 594 | this.saturation[variation] = s; 595 | return this.value[variation] = v; 596 | }; 597 | 598 | mutablecolor.prototype.set_variant_preset = function(p) { 599 | var i, m, results; 600 | results = []; 601 | for (i = m = 0; m <= 3; i = ++m) { 602 | results.push(this.set_variant(i, p[2 * i], p[2 * i + 1])); 603 | } 604 | return results; 605 | }; 606 | 607 | mutablecolor.prototype.get_hex = function(web_safe, variation) { 608 | var c, color, formatted, i, k, len1, len2, m, max, min, n, ref1, rgb, rgbVal, s, str, v; 609 | max = Math.max.apply(Math, (function() { 610 | var len1, m, ref1, results; 611 | ref1 = ['red', 'green', 'blue']; 612 | results = []; 613 | for (m = 0, len1 = ref1.length; m < len1; m++) { 614 | color = ref1[m]; 615 | results.push(this["base_" + color]); 616 | } 617 | return results; 618 | }).call(this)); 619 | min = Math.min.apply(Math, (function() { 620 | var len1, m, ref1, results; 621 | ref1 = ['red', 'green', 'blue']; 622 | results = []; 623 | for (m = 0, len1 = ref1.length; m < len1; m++) { 624 | color = ref1[m]; 625 | results.push(this["base_" + color]); 626 | } 627 | return results; 628 | }).call(this)); 629 | v = (variation < 0 ? this.base_value : this.get_value(variation)) * 255; 630 | s = variation < 0 ? this.base_saturation : this.get_saturation(variation); 631 | k = max > 0 ? v / max : 0; 632 | rgb = []; 633 | ref1 = ['red', 'green', 'blue']; 634 | for (m = 0, len1 = ref1.length; m < len1; m++) { 635 | color = ref1[m]; 636 | rgbVal = Math.min.apply(Math, [255, Math.round(v - (v - this["base_" + color] * k) * s)]); 637 | rgb.push(rgbVal); 638 | } 639 | if (web_safe) { 640 | rgb = (function() { 641 | var len2, n, results; 642 | results = []; 643 | for (n = 0, len2 = rgb.length; n < len2; n++) { 644 | c = rgb[n]; 645 | results.push(Math.round(c / 51) * 51); 646 | } 647 | return results; 648 | })(); 649 | } 650 | formatted = ""; 651 | for (n = 0, len2 = rgb.length; n < len2; n++) { 652 | i = rgb[n]; 653 | str = i.toString(16); 654 | if (str.length < 2) { 655 | str = "0" + str; 656 | } 657 | formatted += str; 658 | } 659 | return formatted; 660 | }; 661 | 662 | return mutablecolor; 663 | 664 | })(); 665 | 666 | return ColorScheme; 667 | 668 | })(); 669 | 670 | if ((typeof module !== "undefined" && module !== null) && (module.exports != null)) { 671 | module.exports = ColorScheme; 672 | } else { 673 | if (typeof define === 'function' && define.amd) { 674 | define([], function() { 675 | return ColorScheme; 676 | }); 677 | } else { 678 | window.ColorScheme = ColorScheme; 679 | } 680 | } 681 | 682 | }).call(this); 683 | 684 | //# sourceMappingURL=color-scheme.js.map 685 | -------------------------------------------------------------------------------- /lib/color-scheme.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "color-scheme.js", 4 | "sourceRoot": "..", 5 | "sources": [ 6 | "src/lib/color-scheme.coffee" 7 | ], 8 | "names": [], 9 | "mappings": ";AACA;AAAA,MAAA,WAAA;IAAA;;EAAM;AAGJ,QAAA;;IAAA,WAAA,GAAc,KAAK,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iBAAA,uCAAA;;2BAAA,IAAI,CAAC,KAAL,CAAW,CAAA,GAAI,EAAf,CAAA,GAAqB;AAArB;;eADV;;QAGA,SAAA,GAAY;AACZ,aAAA,uCAAA;;UACE,GAAA,GAAM,CAAC,CAAC,QAAF,CAAW,EAAX;UACN,IAAG,GAAG,CAAC,MAAJ,GAAa,CAAhB;YACE,GAAA,GAAM,GAAA,GAAI,IADZ;;UAGA,SAAA,IAAa;AALf;AAQA,eAAO;MA1BA;;;;;;;;;;EA4Bb,IAAG,kDAAA,IAAY,wBAAf;IACE,MAAM,CAAC,OAAP,GAAiB,YADnB;GAAA,MAAA;IAGE,IAAG,OAAO,MAAP,KAAiB,UAAjB,IAAgC,MAAM,CAAC,GAA1C;MACE,MAAA,CAAO,EAAP,EAAW,SAAA;AACT,eAAO;MADE,CAAX,EADF;KAAA,MAAA;MAIE,MAAM,CAAC,WAAP,GAAqB,YAJvB;KAHF;;AA/kBA" 10 | } -------------------------------------------------------------------------------- /lib/color-scheme.min.js: -------------------------------------------------------------------------------- 1 | (function(){var t,e=[].slice;t=function(){function t(){var e,n;for(e=[],n=1;n<=4;n++)e.push(new t.mutablecolor(60));this.col=e,this._scheme="mono",this._distance=.5,this._web_safe=!1,this._add_complement=!1}var n,r,o,a,i,u;for(i=Array.isArray||function(t){return"[object Array]"==={}.toString.call(t)},t.SCHEMES={},a="mono monochromatic contrast triade tetrade analogic".split(/\s+/),r=0,o=a.length;r=u;n=0<=u?++o:--o)for(r=a=0;a<=3;r=++a)i[4*n+r]=this.col[n].get_hex(this._web_safe,r);return i},t.prototype.colorset=function(){var t,e;for(t=n(this.colors()),e=[];t.length>0;)e.push(t.splice(0,4));return e},t.prototype.from_hue=function(t){if(null==t)throw"from_hue needs an argument";return this.col[0].set_hue(t),this},t.prototype.rgb2ryb=function(){var t,n,r,o,a,u,s,h,l;return s=1<=arguments.length?e.call(arguments,0):[],null!=s[0]&&i(s[0])&&(s=s[0]),u=s[0],n=s[1],t=s[2],h=Math.min(u,n,t),u-=h,n-=h,t-=h,o=Math.max(u,n,t),l=Math.min(u,n),u-=l,n-=l,t>0&&n>0&&(t/=2,n/=2),l+=n,t+=n,a=Math.max(u,l,t),a>0&&(r=o/a,u*=r,l*=r,t*=r),u+=h,l+=h,t+=h,[Math.floor(u),Math.floor(l),Math.floor(t)]},t.prototype.rgb2hsv=function(){var t,n,r,o,a,u,s,h,l,c;return h=1<=arguments.length?e.call(arguments,0):[],null!=h[0]&&i(h[0])&&(h=h[0]),s=h[0],r=h[1],t=h[2],s/=255,r/=255,t/=255,u=Math.min.apply(Math,[s,r,t]),a=Math.max.apply(Math,[s,r,t]),n=a-u,c=a,n>0?(l=n/a,o=s===a?(r-t)/n:r===a?2+(t-s)/n:4+(s-r)/n,o*=60,o%=360,[o,l,c]):[0,0,c]},t.prototype.rgbToHsv=function(){var t,n,r,o,a,u,s,h,l,c;if(h=1<=arguments.length?e.call(arguments,0):[],null!=h[0]&&i(h[0])&&(h=h[0]),s=h[0],r=h[1],t=h[2],s/=255,r/=255,t/=255,a=Math.max(s,r,t),u=Math.min(s,r,t),o=void 0,l=void 0,c=a,n=a-u,l=0===a?0:n/a,a===u)o=0;else{switch(a){case s:o=(r-t)/n+(r= 0";if(t>1)throw"distance("+t+") - argument must be <= 1";return this._distance=t,this},t.prototype.scheme=function(e){if(null==e)return this._scheme;if(null==t.SCHEMES[e])throw"'"+e+"' isn't a valid scheme name";return this._scheme=e,this},t.prototype.variation=function(e){if(null==e)throw"variation needs an argument";if(null==t.PRESETS[e])throw"'$v' isn't a valid variation name";return this._set_variant_preset(t.PRESETS[e]),this},t.prototype._set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;n<=3;e=++n)r.push(this.col[e].set_variant_preset(t));return r},n=function(t){var e,r,o;if(null==t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return e="",null!=t.global&&(e+="g"),null!=t.ignoreCase&&(e+="i"),null!=t.multiline&&(e+="m"),null!=t.sticky&&(e+="y"),new RegExp(t.source,e);o=new t.constructor;for(r in t)o[r]=n(t[r]);return o},t.mutablecolor=function(){function e(e){if(null==e)throw"No hue specified";this.saturation=[],this.value=[],this.base_red=0,this.base_green=0,this.base_blue=0,this.base_saturation=0,this.base_value=0,this.set_hue(e),this.set_variant_preset(t.PRESETS.default)}return e.prototype.hue=0,e.prototype.saturation=[],e.prototype.value=[],e.prototype.base_red=0,e.prototype.base_green=0,e.prototype.base_saturation=0,e.prototype.base_value=0,e.prototype.get_hue=function(){return this.hue},e.prototype.set_hue=function(e){var n,r,o,a,i,u,s,h,l,c;n=function(t,e,n){return t+Math.round((e-t)*n)},this.hue=Math.round(e%360),i=this.hue%15+(this.hue-Math.floor(this.hue)),c=i/15,u=this.hue-Math.floor(i),s=(u+15)%360,360===u&&(u=0),360===s&&(s=0),o=t.COLOR_WHEEL[u],a=t.COLOR_WHEEL[s],h={red:0,green:1,blue:2,value:3};for(r in h)l=h[r],this["base_"+r]=n(o[l],a[l],c);return this.base_saturation=n(100,100,c)/100,this.base_value/=100},e.prototype.rotate=function(t){var e;return e=(this.hue+t)%360,this.set_hue(e)},e.prototype.get_saturation=function(t){var e,n;return n=this.saturation[t],e=n<0?-n*this.base_saturation:n,e>1&&(e=1),e<0&&(e=0),e},e.prototype.get_value=function(t){var e,n;return n=this.value[t],e=n<0?-n*this.base_value:n,e>1&&(e=1),e<0&&(e=0),e},e.prototype.set_variant=function(t,e,n){return this.saturation[t]=e,this.value[t]=n},e.prototype.set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;n<=3;e=++n)r.push(this.set_variant(e,t[2*e],t[2*e+1]));return r},e.prototype.get_hex=function(t,e){var n,r,o,a,i,u,s,h,l,c,f,p,_,m,d,v;for(l=Math.max.apply(Math,function(){var t,e,n,o;for(n=["red","green","blue"],o=[],e=0,t=n.length;e0?v/l:0,p=[],f=["red","green","blue"],h=0,u=f.length;h 2 | 3 | 4 | 5 | 6 | Color-scheme-js by c0bra 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 |
17 |
18 |

Color-scheme-js

19 |

Generate pleasant color schemes in JavaScript

20 | 21 |

View the Project on GitHub c0bra/color-scheme-js

22 | 23 | 24 | 29 |
30 |
31 |

Welcome to GitHub Pages.

32 | 33 |

This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:

34 | 35 |
$ cd your_repo_root/repo_name
36 | $ git fetch origin
37 | $ git checkout gh-pages
38 | 
39 | 40 |

If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.

41 | 42 |

Designer Templates

43 | 44 |

We've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.

45 | 46 |

Rather Drive Stick?

47 | 48 |

If you prefer to not use the automatic generator, push a branch named gh-pages to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.

49 | 50 |

Authors and Contributors

51 | 52 |

You can @mention a GitHub username to generate a link to their profile. The resulting <a> element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.

53 | 54 |

Support or Contact

55 | 56 |

Having trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.

57 |
58 |
59 |

This project is maintained by c0bra

60 |

Hosted on GitHub Pages — Theme by orderedlist

61 |
62 |
63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "color-scheme", 3 | "version": "1.0.1", 4 | "description": "Generate pleasant color schemes", 5 | "main": "lib/color-scheme.js", 6 | "types": "index.d.ts", 7 | "scripts": { 8 | "test": "mocha --compilers coffee:coffee-script/register", 9 | "prepublish": "cake build" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/c0bra/color-scheme-js.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/c0bra/color-scheme-js/issues" 17 | }, 18 | "keywords": [ 19 | "color", 20 | "scheme", 21 | "generator", 22 | "random", 23 | "picker", 24 | "web" 25 | ], 26 | "author": "Brian Hann", 27 | "license": "MIT", 28 | "dependencies": {}, 29 | "devDependencies": { 30 | "coffee-script": "^1.12.6", 31 | "uglify-js": "^2.7.5", 32 | "mocha": "^3.2.0", 33 | "chai": "^3.5.0", 34 | "which": "^1.0.5" 35 | } 36 | } -------------------------------------------------------------------------------- /params.json: -------------------------------------------------------------------------------- 1 | {"name":"Color-scheme-js","tagline":"Generate pleasant color schemes in JavaScript","body":"### Welcome to GitHub Pages.\r\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:\r\n\r\n```\r\n$ cd your_repo_root/repo_name\r\n$ git fetch origin\r\n$ git checkout gh-pages\r\n```\r\n\r\nIf you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.\r\n\r\n### Designer Templates\r\nWe've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.\r\n\r\n### Rather Drive Stick?\r\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\r\n\r\n### Authors and Contributors\r\nYou can @mention a GitHub username to generate a link to their profile. The resulting `` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} -------------------------------------------------------------------------------- /src/lib/color-scheme.coffee: -------------------------------------------------------------------------------- 1 | 2 | class ColorScheme 3 | 4 | # Helper 5 | typeIsArray = Array.isArray || ( value ) -> return {}.toString.call( value ) is '[object Array]' 6 | 7 | # List of possible color scheme types 8 | @SCHEMES = {}; 9 | @SCHEMES[word] = true for word in "mono monochromatic contrast triade tetrade analogic".split /\s+/ 10 | 11 | @PRESETS = 12 | default : [ -1, -1, 1, -0.7, 0.25, 1, 0.5, 1 ], 13 | pastel : [ 0.5, -0.9, 0.5, 0.5, 0.1, 0.9, 0.75, 0.75 ] 14 | soft : [ 0.3, -0.8, 0.3, 0.5, 0.1, 0.9, 0.5, 0.75 ] 15 | light : [ 0.25, 1, 0.5, 0.75, 0.1, 1, 0.5, 1 ] 16 | hard : [ 1, -1, 1, -0.6, 0.1, 1, 0.6, 1 ] 17 | pale : [ 0.1, -0.85, 0.1, 0.5, 0.1, 1, 0.1, 0.75 ] 18 | 19 | @COLOR_WHEEL = 20 | # hue => [ red, green, blue, value ] 21 | 0 : [ 255, 0, 0, 100 ] 22 | 15 : [ 255, 51, 0, 100 ] 23 | 30 : [ 255, 102, 0, 100 ] 24 | 45 : [ 255, 128, 0, 100 ] 25 | 60 : [ 255, 153, 0, 100 ] 26 | 75 : [ 255, 178, 0, 100 ] 27 | 90 : [ 255, 204, 0, 100 ] 28 | 105 : [ 255, 229, 0, 100 ] 29 | 120 : [ 255, 255, 0, 100 ] 30 | 135 : [ 204, 255, 0, 100 ] 31 | 150 : [ 153, 255, 0, 100 ] 32 | 165 : [ 51, 255, 0, 100 ] 33 | 180 : [ 0, 204, 0, 80 ] 34 | 195 : [ 0, 178, 102, 70 ] 35 | 210 : [ 0, 153, 153, 60 ] 36 | 225 : [ 0, 102, 178, 70 ] 37 | 240 : [ 0, 51, 204, 80 ] 38 | 255 : [ 25, 25, 178, 70 ] 39 | 270 : [ 51, 0, 153, 60 ] 40 | 285 : [ 64, 0, 153, 60 ] 41 | 300 : [ 102, 0, 153, 60 ] 42 | 315 : [ 153, 0, 153, 60 ] 43 | 330 : [ 204, 0, 153, 80 ] 44 | 345 : [ 229, 0, 102, 90 ] 45 | 46 | constructor: () -> 47 | colors = [] 48 | colors.push(new ColorScheme.mutablecolor(60)) for [1..4] 49 | 50 | @col = colors 51 | @_scheme = 'mono' 52 | @_distance = 0.5 53 | @_web_safe = false 54 | @_add_complement = false 55 | 56 | 57 | ### 58 | 59 | colors() 60 | 61 | Returns an array of 4, 8, 12 or 16 colors in RRGGBB hexidecimal notation 62 | (without a leading "#") depending on the color scheme and addComplement 63 | parameter. For each set of four, the first is usually the most saturated color, 64 | the second a darkened version, the third a pale version and fourth 65 | a less-pale version. 66 | 67 | For example: With a contrast scheme, "colors()" would return eight colors. 68 | Indexes 1 and 5 could be background colors, 2 and 6 could be foreground colors. 69 | 70 | Trust me, it's much better if you check out the Color Scheme web site, whose 71 | URL is listed in "Description" 72 | 73 | ### 74 | 75 | colors: () -> 76 | used_colors = 1; 77 | h = @col[0].get_hue() 78 | 79 | # Should these be fat arrows (=>) so that the @ refers to the right object? 80 | dispatch = 81 | mono : () => 82 | contrast : () => 83 | used_colors = 2; 84 | @col[1].set_hue h 85 | @col[1].rotate(180) 86 | 87 | triade : () => 88 | used_colors = 3 89 | dif = 60 * @_distance 90 | @col[1].set_hue h 91 | @col[1].rotate 180 - dif 92 | @col[2].set_hue h 93 | @col[2].rotate 180 + dif 94 | 95 | tetrade : () => 96 | used_colors = 4 97 | dif = 90 * @_distance 98 | @col[1].set_hue h 99 | @col[1].rotate 180 100 | @col[2].set_hue h 101 | @col[2].rotate 180 + dif 102 | @col[3].set_hue h 103 | @col[3].rotate dif 104 | 105 | analogic : () => 106 | used_colors = if @_add_complement then 4 else 3 107 | dif = 60 * @_distance 108 | 109 | # console.log "@col", @col 110 | 111 | @col[1].set_hue h 112 | @col[1].rotate dif 113 | @col[2].set_hue h 114 | @col[2].rotate 360 - dif 115 | @col[3].set_hue h 116 | @col[3].rotate 180 117 | 118 | # Alias for monochromatic 119 | dispatch['monochromatic'] = dispatch['mono'] 120 | 121 | if dispatch[@_scheme]? 122 | dispatch[@_scheme]() 123 | else 124 | throw "Unknown color scheme name: #{@_scheme}" 125 | 126 | output = [] 127 | 128 | for i in [0 .. used_colors - 1] 129 | for j in [0..3] 130 | output[i * 4 + j] = @col[i].get_hex(@_web_safe, j) 131 | 132 | return output 133 | 134 | ### 135 | 136 | colorset() 137 | 138 | Returns a list of lists of the colors in groups of four. This method simply 139 | allows you to reference a color in the scheme by its group isntead of its 140 | absolute index in the list of colors. I am assuming that "colorset()" 141 | will make it easier to use this module with the templating systems that are 142 | out there. 143 | 144 | For example, if you were to follow the synopsis, say you wanted to retrieve 145 | the two darkest colors from the first two groups of the scheme, which is 146 | typically the second color in the group. You could retrieve them with 147 | "colors()" 148 | 149 | first_background = (scheme.colors())[1]; 150 | second_background = (scheme.colors())[5]; 151 | 152 | Or, with this method, 153 | 154 | first_background = (scheme.colorset())[0][1] 155 | second_background = (scheme.colorset())[1][1] 156 | 157 | ### 158 | 159 | colorset: () -> 160 | flat_colors = clone @colors() 161 | grouped_colors = [] 162 | grouped_colors.push(flat_colors.splice(0, 4)) while flat_colors.length > 0 163 | return grouped_colors 164 | 165 | 166 | ### 167 | 168 | from_hue( degrees ) 169 | 170 | Sets the base color hue, where 'degrees' is an integer. (Values greater than 171 | 359 and less than 0 wrap back around the wheel.) 172 | 173 | The default base hue is 0, or bright red. 174 | 175 | ### 176 | 177 | from_hue: (h) -> 178 | throw "from_hue needs an argument" if !h? 179 | 180 | @col[0].set_hue h 181 | return this # chaining 182 | 183 | rgb2ryb: (rgb...) -> 184 | rgb = rgb[0] if rgb[0]? and typeIsArray(rgb[0]) 185 | 186 | [red, green, blue] = rgb 187 | 188 | # Remove the white from the color 189 | white = Math.min(red, green, blue) 190 | red -= white 191 | green -= white 192 | blue -= white 193 | maxgreen = Math.max(red, green, blue) 194 | 195 | # Get the yellow out of the red+green 196 | yellow = Math.min(red, green) 197 | red -= yellow 198 | green -= yellow 199 | 200 | # If this unfortunate conversion combines blue and green, then cut each in half to 201 | # preserve the value's maximum range. 202 | if blue > 0 and green > 0 203 | blue /= 2 204 | green /= 2 205 | 206 | # Redistribute the remaining green. 207 | yellow += green 208 | blue += green 209 | 210 | # Normalize to values. 211 | maxyellow = Math.max(red, yellow, blue) 212 | if maxyellow > 0 213 | iN = maxgreen / maxyellow 214 | red *= iN 215 | yellow *= iN 216 | blue *= iN 217 | 218 | # Add the white back in. 219 | red += white 220 | yellow += white 221 | blue += white 222 | 223 | return [ 224 | Math.floor(red) 225 | Math.floor(yellow) 226 | Math.floor(blue) 227 | ] 228 | 229 | # --- 230 | # generated by js2coffee 2.2.0 231 | 232 | rgb2hsv: (rgb...) -> 233 | # Handle being passed either a list of arguments, or an array 234 | rgb = rgb[0] if rgb[0]? and typeIsArray(rgb[0]) 235 | 236 | [r, g, b] = rgb 237 | 238 | r /= 255 239 | g /= 255 240 | b /= 255 241 | 242 | min = Math.min [r, g, b]... 243 | max = Math.max [r, g, b]... 244 | d = max - min 245 | v = max 246 | 247 | # console. "minmax", min, max, d, v 248 | 249 | s 250 | if ( d > 0 ) 251 | s = d / max 252 | else 253 | return [ 0, 0, v ] 254 | 255 | h = ( 256 | if (r is max) then ((g - b) / d) 257 | else ( 258 | if (g is max) then (2 + (b - r) / d) 259 | else (4 + (r - g) / d) 260 | ) 261 | ) 262 | 263 | h *= 60 264 | h %= 360 265 | 266 | # if (h < 0) 267 | # h = 360 - h 268 | 269 | [h, s, v] 270 | 271 | rgbToHsv: (rgb...) -> 272 | rgb = rgb[0] if rgb[0]? and typeIsArray(rgb[0]) 273 | [r, g, b] = rgb 274 | 275 | # [r, g, b] = @rgb2ryb [r, g, b] 276 | 277 | r /= 255 278 | g /= 255 279 | b /= 255 280 | 281 | max = Math.max(r, g, b) 282 | min = Math.min(r, g, b) 283 | 284 | h = undefined 285 | s = undefined 286 | v = max 287 | d = max - min 288 | s = if max == 0 then 0 else d / max 289 | 290 | if max == min 291 | h = 0 292 | # achromatic 293 | else 294 | switch max 295 | when r 296 | h = (g - b) / d + (if g < b then 6 else 0) 297 | when g 298 | h = (b - r) / d + 2 299 | when b 300 | h = (r - g) / d + 4 301 | h /= 6 302 | 303 | [h, s, v] 304 | 305 | ### 306 | 307 | from_hex( color ) 308 | 309 | Sets the base color to the given color, where 'color' is in the hexidecimal 310 | form RRGGBB. 'color' should not be preceded with a hash (#). 311 | 312 | The default base color is the equivalent of #ff0000, or bright red. 313 | 314 | ### 315 | 316 | from_hex: (hex) -> 317 | throw "from_hex needs an argument" if !hex? 318 | throw "from_hex(#{hex}) - argument must be in the form of RRGGBB" unless /// ^ ( [0-9A-F]{2} ) {3} $ ///im.test(hex) 319 | 320 | rgbcap = /(..)(..)(..)/.exec(hex)[1..3] 321 | [r, g, b] = (parseInt(num, 16) for num in rgbcap) 322 | 323 | [r, g, b] = @rgb2ryb [r, g, b] 324 | 325 | hsv = @rgbToHsv(r, g, b) 326 | 327 | h0 = hsv[0] 328 | h1 = 0 329 | h2 = 1000 330 | i1 = null 331 | i2 = null 332 | h = null 333 | s = null 334 | v = null 335 | 336 | # NOTE: I honestly have no idea what this code was doing but it seems to work fine without it... 337 | # wheelKeys = []; wheelKeys.push i for own i of ColorScheme.COLOR_WHEEL 338 | # for i of wheelKeys.sort( (a, b) -> a - b ) 339 | # c = ColorScheme.COLOR_WHEEL[ wheelKeys[i] ] 340 | # 341 | # hsv1 = @rgbToHsv( i for i in c[ 0 .. 2 ] ) 342 | # h = hsv1[0] 343 | # if h >= h1 and h <= h0 344 | # h1 = h 345 | # i1 = i 346 | # if h <= h2 and h >= h0 347 | # h2 = h 348 | # i2 = i 349 | # 350 | # if h2 == 0 or h2 > 360 351 | # h2 = 360 352 | # i2 = 360 353 | # 354 | # k = if ( h2 != h1 ) then ( h0 - h1 ) / ( h2 - h1 ) else 0 355 | # h = Math.round( i1 + k * ( i2 - i1 ) ) 356 | # h %= 360 357 | 358 | h = hsv[0] 359 | s = hsv[1] 360 | v = hsv[2] 361 | 362 | @from_hue h * 360 363 | @_set_variant_preset( [ s, v, s, v * 0.7, s * 0.25, 1, s * 0.5, 1 ] ) 364 | 365 | return this 366 | 367 | ### 368 | 369 | add_complement( BOOLEAN ) 370 | 371 | If BOOLEAN is true, an extra set of colors will be produced using the 372 | complement of the selected color. 373 | 374 | This only works with the analogic color scheme. The default is false. 375 | 376 | ### 377 | 378 | add_complement: (b) -> 379 | throw "add_complement needs an argument" if !b? 380 | @_add_complement = b 381 | return this 382 | 383 | ### 384 | 385 | web_safe( BOOL ) 386 | 387 | Sets whether the colors returned by L<"colors()"> or L<"colorset()"> will be 388 | web-safe. 389 | 390 | The default is false. 391 | 392 | ### 393 | 394 | web_safe: (b) -> 395 | throw "web_safe needs an argument" if !b? 396 | @_web_safe = b 397 | return this 398 | 399 | ### 400 | 401 | distance( FLOAT ) 402 | 403 | 'FLOAT'> must be a value from 0 to 1. You might use this with the "triade" 404 | "tetrade" or "analogic" color schemes. 405 | 406 | The default is 0.5. 407 | 408 | ### 409 | 410 | distance: (d) -> 411 | throw "distance needs an argument" if !d? 412 | throw "distance(#{d}) - argument must be >= 0" if d < 0 413 | throw "distance(#{d}) - argument must be <= 1" if d > 1 414 | @_distance = d 415 | return this 416 | 417 | ### 418 | 419 | scheme( name ) 420 | 421 | 'name' must be a valid color scheme name. See "Color Schemes". The default 422 | is "mono" 423 | 424 | ### 425 | 426 | scheme: (name) -> 427 | if !name? 428 | return @_scheme 429 | else 430 | throw "'#{name}' isn't a valid scheme name" unless ColorScheme.SCHEMES[name]? 431 | @_scheme = name 432 | return this 433 | 434 | ### 435 | 436 | variation( name ) 437 | 438 | 'name' must be a valid color variation name. See "Color Variations" 439 | 440 | ### 441 | 442 | variation: (v) -> 443 | throw "variation needs an argument" unless v? 444 | throw "'$v' isn't a valid variation name" unless ColorScheme.PRESETS[v]? 445 | @_set_variant_preset ColorScheme.PRESETS[v] 446 | return this 447 | 448 | _set_variant_preset: (p) -> 449 | @col[i].set_variant_preset(p) for i in [0 .. 3] 450 | 451 | clone = (obj) -> 452 | if not obj? or typeof obj isnt 'object' 453 | return obj 454 | 455 | if obj instanceof Date 456 | return new Date(obj.getTime()) 457 | 458 | if obj instanceof RegExp 459 | flags = '' 460 | flags += 'g' if obj.global? 461 | flags += 'i' if obj.ignoreCase? 462 | flags += 'm' if obj.multiline? 463 | flags += 'y' if obj.sticky? 464 | return new RegExp(obj.source, flags) 465 | 466 | newInstance = new obj.constructor() 467 | 468 | for key of obj 469 | newInstance[key] = clone obj[key] 470 | 471 | return newInstance 472 | 473 | # End ColorScheme class # 474 | 475 | 476 | 477 | # Subclass for mutable colors # 478 | class @mutablecolor 479 | hue : 0 480 | saturation : [] 481 | value : [] 482 | base_red : 0 483 | base_green : 0 484 | base_saturation : 0 485 | base_value : 0 486 | 487 | constructor: (hue) -> 488 | throw "No hue specified" if !hue? 489 | 490 | @saturation = [] 491 | @value = [] 492 | @base_red = 0 493 | @base_green = 0 494 | @base_blue = 0 495 | @base_saturation = 0 496 | @base_value = 0 497 | @set_hue hue 498 | 499 | @set_variant_preset ColorScheme.PRESETS['default'] 500 | 501 | get_hue: () -> 502 | @hue 503 | 504 | set_hue: (h) -> 505 | avrg = (a, b, k) -> 506 | a + Math.round( ( b - a ) * k ) 507 | 508 | @hue = Math.round h % 360 509 | d = @hue % 15 + ( @hue - Math.floor( @hue ) ); 510 | k = d / 15; 511 | 512 | derivative1 = @hue - Math.floor(d) 513 | derivative2 = ( derivative1 + 15 ) % 360 514 | 515 | if derivative1 == 360 516 | derivative1 = 0 517 | 518 | if derivative2 == 360 519 | derivative2 = 0 520 | 521 | colorset1 = ColorScheme.COLOR_WHEEL[derivative1] 522 | colorset2 = ColorScheme.COLOR_WHEEL[derivative2] 523 | 524 | en = 525 | red: 0 526 | green: 1 527 | blue: 2 528 | value: 3 529 | 530 | # while ( my ( $color, $i ) = each %enum ) { 531 | for color, i of en 532 | this["base_#{color}"] = avrg( colorset1[i], colorset2[i], k ) 533 | 534 | @base_saturation = avrg( 100, 100, k ) / 100 535 | @base_value /= 100 536 | 537 | # Rotate the hue a certain number of degrees 538 | rotate: (angle) -> 539 | newhue = ( @hue + angle ) % 360; 540 | @set_hue newhue 541 | 542 | get_saturation: (variation) -> 543 | x = @saturation[variation] 544 | s = if x < 0 then -x * @base_saturation else x 545 | s = 1 if s > 1 546 | s = 0 if s < 0 547 | return s 548 | 549 | get_value: (variation) -> 550 | x = @value[variation] 551 | v = if x < 0 then -x * @base_value else x 552 | v = 1 if v > 1 553 | v = 0 if v < 0 554 | return v 555 | 556 | set_variant: (variation, s, v) -> 557 | # console.log "set_variant(#{variation}, #{s}, #{v}) on #{this}" 558 | @saturation[variation] = s 559 | @value[variation] = v 560 | 561 | set_variant_preset: (p) -> 562 | # console.log "set_variant_preset(#{p})" 563 | @set_variant( i, p[ 2 * i ], p[ 2 * i + 1 ] ) for i in [0 .. 3] 564 | 565 | get_hex: (web_safe, variation) -> 566 | max = Math.max ( this["base_#{color}"] for color in ['red', 'green', 'blue'] )... 567 | min = Math.min ( this["base_#{color}"] for color in ['red', 'green', 'blue'] )... 568 | 569 | v = ( if variation < 0 then @base_value else @get_value(variation) ) * 255 570 | 571 | s = if variation < 0 then @base_saturation else @get_saturation(variation) 572 | k = if max > 0 then v / max else 0 573 | 574 | rgb = [] 575 | for color in ['red', 'green', 'blue'] 576 | rgbVal = Math.min [ 255, Math.round(v - ( v - this["base_#{color}"] * k ) * s) ]... 577 | rgb.push rgbVal 578 | 579 | if web_safe 580 | rgb = ( Math.round(c / 51) * 51 for c in rgb ) 581 | 582 | formatted = "" 583 | for i in rgb 584 | str = i.toString(16) 585 | if str.length < 2 586 | str = "0"+str 587 | 588 | formatted += str 589 | 590 | 591 | return formatted 592 | 593 | if module? and module.exports? 594 | module.exports = ColorScheme 595 | else 596 | if typeof define == 'function' and define.amd 597 | define [], () -> 598 | return ColorScheme 599 | else 600 | window.ColorScheme = ColorScheme 601 | -------------------------------------------------------------------------------- /test.coffee: -------------------------------------------------------------------------------- 1 | cs = require './src/lib/color-scheme' 2 | 3 | scheme = new cs().from_hex '00ff00' 4 | 5 | console.log scheme.col[0].hue 6 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const ColorScheme = require('./lib/color-scheme'); 2 | 3 | const mainColor = '000000'; 4 | 5 | let scheme = new ColorScheme(); 6 | scheme.from_hex(mainColor) 7 | .scheme('triade') 8 | .distance(0.7) 9 | .variation('pastel'); 10 | -------------------------------------------------------------------------------- /test/mutablecolor.coffee: -------------------------------------------------------------------------------- 1 | 2 | chai = require 'chai' 3 | should = chai.should() 4 | 5 | ColorScheme = require '../src/lib/color-scheme' 6 | 7 | describe 'ColorScheme class', -> 8 | describe '"mutablecolor" subclass', -> 9 | it 'should exist', -> 10 | ColorScheme.mutablecolor.should.exist 11 | it 'should be a function', -> 12 | ColorScheme.mutablecolor.should.be.a 'function' 13 | 14 | describe '"mutablecolor"', -> 15 | describe 'constructor', -> 16 | describe 'with no hue specified', -> 17 | it 'should throw "No hue specified"', -> 18 | (() -> 19 | new ColorScheme.mutablecolor() 20 | ).should.Throw("No hue specified") 21 | describe 'with a hue specified', -> 22 | it 'should be a ColorScheme.mutablecolor object', -> 23 | color = new ColorScheme.mutablecolor(50) 24 | color.should.be instanceof ColorScheme.mutablecolor -------------------------------------------------------------------------------- /test/test.coffee: -------------------------------------------------------------------------------- 1 | 2 | chai = require 'chai' 3 | chai.should() 4 | 5 | ColorScheme = require '../src/lib/color-scheme' 6 | #ColorScheme = require '../lib/color-scheme.min' 7 | 8 | describe 'ColorScheme class', -> 9 | describe 'SCHEMES Object', -> 10 | it 'should exist', -> 11 | ColorScheme.SCHEMES.should.exist 12 | it 'should be an object', -> 13 | ColorScheme.SCHEMES.should.be.a 'object' 14 | it 'should have property for "mono"', -> 15 | ColorScheme.SCHEMES.mono.should.exist 16 | it 'should have property for "contrast"', -> 17 | ColorScheme.SCHEMES.contrast.should.exist 18 | 19 | describe 'PRESETS object', -> 20 | it 'should exist', -> 21 | ColorScheme.PRESETS.should.exist 22 | it 'should have a property for "default"', -> 23 | ColorScheme.PRESETS.default.should.exist 24 | 25 | describe 'COLOR_WHEEL object', -> 26 | it 'should exist', -> 27 | ColorScheme.COLOR_WHEEL.should.exist 28 | 29 | describe 'scheme()', -> 30 | s = null 31 | beforeEach -> 32 | s = new ColorScheme 33 | 34 | it 'should not throw with no argument', -> 35 | (() -> 36 | s.scheme() 37 | ).should.not.throw() 38 | it 'should return the current scheme', -> 39 | s.scheme 'mono' 40 | ret = s.scheme() 41 | ret.should.equal 'mono' 42 | ret.should.equal s._scheme 43 | 44 | 45 | describe 'ColorScheme instance', -> 46 | scheme = new ColorScheme 47 | it 'should be a ColorScheme object', -> 48 | scheme.should.be instanceof ColorScheme 49 | 50 | it 'should have a working from_hex() method', -> 51 | (() -> 52 | scheme.from_hex('ff0000') 53 | ).should.not.Throw() 54 | 55 | it 'from_hex() should not throw with a good value', -> 56 | (() -> 57 | scheme.from_hex('ad1457') 58 | scheme.from_hex('790001') 59 | ).should.not.Throw() 60 | 61 | describe 'rgb2hsv', -> 62 | scheme = new ColorScheme 63 | 64 | it.only 'should convert rgb values to hsv properly', -> 65 | scheme.rgbToHsv(0, 255, 0).should.eql [1/3, 1, 1] 66 | 67 | describe 'from_hex', -> 68 | scheme = new ColorScheme 69 | 70 | it.only 'should select the correct hue', -> 71 | scheme.from_hex('00ff00') 72 | scheme.col[0].hue.should.equal 180 73 | 74 | 75 | # scm = new ColorScheme 76 | 77 | # scm.from_hue(21) 78 | # .scheme('triade') 79 | # .distance(0.1) 80 | # .add_complement(false) 81 | # .variation('pastel') 82 | # .web_safe(true) 83 | 84 | # # # console.log eyes.inspect(scm) 85 | 86 | # list = scm.colors() 87 | # console.log list 88 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.7.1 2 | var ColorScheme, chai; 3 | 4 | chai = require('chai'); 5 | 6 | chai.should(); 7 | 8 | ColorScheme = require('../src/lib/color-scheme'); 9 | 10 | describe('ColorScheme class', function() { 11 | describe('SCHEMES Object', function() { 12 | it('should exist', function() { 13 | return ColorScheme.SCHEMES.should.exist; 14 | }); 15 | it('should be an object', function() { 16 | return ColorScheme.SCHEMES.should.be.a('object'); 17 | }); 18 | it('should have property for "mono"', function() { 19 | return ColorScheme.SCHEMES.mono.should.exist; 20 | }); 21 | return it('should have property for "contrast"', function() { 22 | return ColorScheme.SCHEMES.contrast.should.exist; 23 | }); 24 | }); 25 | describe('PRESETS object', function() { 26 | it('should exist', function() { 27 | return ColorScheme.PRESETS.should.exist; 28 | }); 29 | return it('should have a property for "default"', function() { 30 | return ColorScheme.PRESETS["default"].should.exist; 31 | }); 32 | }); 33 | describe('COLOR_WHEEL object', function() { 34 | return it('should exist', function() { 35 | return ColorScheme.COLOR_WHEEL.should.exist; 36 | }); 37 | }); 38 | return describe('scheme()', function() { 39 | var s; 40 | s = null; 41 | beforeEach(function() { 42 | return s = new ColorScheme; 43 | }); 44 | it('should not throw with no argument', function() { 45 | return (function() { 46 | return s.scheme(); 47 | }).should.not["throw"](); 48 | }); 49 | return it('should return the current scheme', function() { 50 | var ret; 51 | s.scheme('mono'); 52 | ret = s.scheme(); 53 | ret.should.equal('mono'); 54 | return ret.should.equal(s._scheme); 55 | }); 56 | }); 57 | }); 58 | 59 | describe('ColorScheme instance', function() { 60 | var scheme; 61 | scheme = new ColorScheme; 62 | it('should be a ColorScheme object', function() { 63 | return scheme.should.be instanceof ColorScheme; 64 | }); 65 | it('should have a working from_hex() method', function() { 66 | return (function() { 67 | return scheme.from_hex('ff0000'); 68 | }).should.not.Throw(); 69 | }); 70 | return it(' from_hex() should not throw with ', function() { 71 | return (function() { 72 | scheme.from_hex('ad1457'); 73 | return scheme.from_hex('790001'); 74 | }).should.not.Throw(); 75 | }); 76 | }); 77 | --------------------------------------------------------------------------------