asciiblaster

- draw irc art in your web browser
git clone git://git.acid.vegas/asciiblaster.git
Log | Files | Refs | Archive | README

color.js (3788B)

      1 
      2 var fillColor = 1  // black
      3 
      4 var color_names = ("white black dark-blue green red dark-red purple orange " +
      5                    "yellow lime teal cyan blue magenta dark-gray light-gray").split(" ");
      6 
      7 var all_color_hue_order = "dark-red red orange yellow lime green teal cyan blue dark-blue purple magenta black dark-gray light-gray white".split(" ");
      8 var all_color_inv_order = "cyan teal blue dark-blue purple magenta dark-red red orange yellow lime green white light-gray dark-gray black".split(" ");
      9 var color_hue_order = "dark-red red orange yellow lime cyan teal blue dark-blue purple magenta".split(" ");
     10 var color_inv_order = "cyan teal blue dark-blue purple magenta dark-red red orange yellow lime green".split(" ");
     11 var gray_names = ("black dark-gray light-gray white").split(" ")
     12 
     13 var fire_names = ("black dark-red red orange yellow white cyan").split(" ")
     14 var red_names = ("black dark-red red").split(" ")
     15 var yellow_names = ("black orange yellow white").split(" ")
     16 var green_names = ("teal green lime").split(" ")
     17 var blue_names = ("black dark-blue blue").split(" ")
     18 var purple_names = ("dark-blue purple magenta red").split(" ")
     19 var dark_gray_names = ("black dark-blue teal dark-gray light-gray white").split(" ")
     20 var color_alphabet = "abcdefghijklmnop";
     21 var colors = {}
     22 color_names.forEach(function(name, i){
     23   colors[name.replace("-", "")] = i
     24   colors[name] = i
     25 })
     26 colors.brown = 5
     27 
     28 function get_inverse (n) { return colors[all_color_inv_order.indexOf(color_names[n])] }
     29 
     30 function mirc_color (n) { return mod(n, 16)|0 }
     31 function mirc_color_reverse (n) { return mod(-(n+1), 16)|0 }
     32 function all_hue (n) { return colors[all_color_hue_order[mod(n, 16)|0]] }
     33 function all_inv_hue (n) { return colors[all_color_inv_order[mod(n, 16)|0]] }
     34 function hue (n) { return colors[color_hue_order[mod(n, 11)|0]] }
     35 function rand_hue () { return colors[color_hue_order[randint(11)]] }
     36 function rand_gray () { return colors[gray_names[randint(4)]] }
     37 function inv_hue (n) { return colors[color_inv_order[mod(n, 11)|0]] }
     38 function gray (n) { return colors[gray_names[mod(n, 4)|0]] }
     39 function fire (n) { return colors[fire_names[mod(n, 7)|0]] }
     40 function red (n) { return colors[red_names[mod(n, 3)|0]] }
     41 function yellow (n) { return colors[yellow_names[mod(n, 4)|0]] }
     42 function green (n) { return colors[green_names[mod(n, 3)|0]] }
     43 function blue (n) { return colors[blue_names[mod(n, 3)|0]] }
     44 function purple (n) { return colors[purple_names[mod(n, 4)|0]] }
     45 function dark_gray (n) { return colors[dark_gray_names[mod(n, 4)|0]] }
     46 
     47 var css_lookup = {
     48   'rgb(255, 255, 255)': 'A',
     49   'rgb(0, 0, 0)': 'B',
     50   'rgb(0, 0, 127)': 'C',
     51   'rgb(0, 147, 0)': 'D',
     52   'red': 'E',
     53   'rgb(127, 0, 0)': 'F',
     54   'rgb(156, 0, 156)': 'G',
     55   'rgb(252, 127, 0)': 'H',
     56   'rgb(255, 255, 0)': 'I',
     57   'rgb(0, 252, 0)': 'J',
     58   'rgb(0, 147, 147)': 'K',
     59   'rgb(0, 255, 255)': 'L',
     60   'rgb(0, 0, 252)': 'M',
     61   'rgb(255, 0, 255)': 'N',
     62   'rgb(127, 127, 127)': 'O',
     63   'rgb(210, 210, 210)': 'P',
     64 };
     65 var css_reverse_lookup = {}
     66 Object.keys(css_lookup).forEach(function(color){
     67   css_reverse_lookup[ css_lookup[color].charCodeAt(0) - 65 ] = color
     68 })
     69 
     70 var ansi_fg = [
     71   97, // white
     72   30, // black
     73   34, // dark blue
     74   32, // green
     75   91, // light red
     76   31, // dark red
     77   35, // purple
     78   33, // "dark yellow" (orange?)
     79   93, // "light yellow"
     80   92, // light green
     81   36, // cyan (teal?)
     82   96, // light cyan
     83   94, // light blue
     84   95, // light magenta
     85   90, // dark gray
     86   37, // light gray
     87 ]
     88 
     89 var ansi_bg = [
     90   107, // white
     91   40,  // black
     92   44,  // dark blue
     93   42,  // green
     94   101, // light red
     95   41,  // dark red
     96   45,  // purple
     97   43,  // yellow (orange)
     98   103, // light yellow
     99   102, // light green
    100   46,  // cyan (teal?)
    101   106, // light cyan
    102   104, // light blue
    103   105, // light magenta
    104   100, // dark gray
    105   47,  // light gray
    106 ]