asciiblaster- draw irc art in your web browser |
git clone git://git.acid.vegas/asciiblaster.git |
Log | Files | Refs | Archive | README |
palette.js (2895B)
1 var palette = (function(){ 2 3 var palette = new Matrix (32, 2, function(x,y){ 4 var lex = new Lex (x,y) 5 return lex 6 }) 7 8 var palette_index = localStorage.getItem("ascii.palette") || 1 9 var palette_list = [all_hue, all_inv_hue, mirc_color, mirc_color_reverse] 10 var palette_fn = palette_list[palette_index] 11 palette.chars = " " + dither.a + dither.b + dither.c 12 13 palette.repaint = function(){ 14 var xw = use_experimental_palette ? 5 : 2 15 if (canvas.vertical) { 16 palette.resize( xw, 16 ) 17 } 18 else { 19 palette.resize( 32, xw ) 20 } 21 22 palette.forEach(function(lex,x,y){ 23 if (canvas.vertical) { x=x^y;y=x^y;x=x^y;x*=2 } 24 if (y < 2) { 25 lex.bg = palette_fn(x>>1) 26 lex.fg = palette_fn(x>>1) 27 } 28 else { 29 lex.bg = fillColor 30 lex.fg = palette_fn(x>>1) 31 } 32 lex.char = palette.chars[y] 33 lex.opacity = 1 34 lex.build() 35 if (lex.char == "_") lex.char = " " 36 }) 37 } 38 palette.repaint() 39 var use_experimental_palette = false 40 palette.experimental = function(state){ 41 use_experimental_palette = typeof state == "boolean" ? state : ! use_experimental_palette 42 use_experimental_palette ? palette.resize(32, 5) : palette.resize(32, 2) 43 palette.repaint() 44 return use_experimental_palette 45 } 46 47 palette.bind = function(){ 48 palette.forEach(function(lex, x, y){ 49 if (lex.bound) return 50 lex.bound = true 51 52 lex.span.addEventListener('mousedown', function(e){ 53 e.preventDefault() 54 if (e.shiftKey) { 55 palette_index = (palette_index+1) % palette_list.length 56 localStorage.setItem("ascii.palette", palette_index) 57 palette_fn = palette_list[palette_index] 58 palette.repaint() 59 return 60 } 61 if (e.ctrlKey || e.which == 3) return 62 if (brush.char == " " && lex.char == " ") { 63 brush.fg = lex.fg 64 brush.bg = lex.bg 65 brush.char = lex.char 66 } 67 else if (lex.char != " ") { 68 brush.fg = lex.bg 69 brush.bg = lex.fg 70 brush.char = lex.char 71 } 72 else { 73 brush.fg = lex.bg 74 brush.bg = fillColor 75 // brush.char = lex.char 76 } 77 brush.opacity = lex.opacity 78 if (! brush.modified) { 79 brush.generate() 80 } 81 if (filling || e.ctrlKey) { 82 fillColor = lex.bg 83 } 84 letters.repaint() 85 }) 86 87 lex.span.addEventListener('contextmenu', function(e){ 88 e.preventDefault() 89 fillColor = y ? lex.fg : lex.bg 90 palette.repaint() 91 brush.fg = lex.fg 92 brush.char = lex.char 93 brush.opacity = lex.opacity 94 brush.generate() 95 brush_rapper.style.borderColor = css_reverse_lookup[fillColor] 96 return 97 }) 98 99 }) 100 } 101 102 brush_rapper.style.borderColor = css_reverse_lookup[fillColor] 103 104 return palette 105 106 })()