| asciiblaster- draw irc art in your web browser | 
| git clone git://git.acid.vegas/asciiblaster.git | 
| Log | Files | Refs | Archive | README | 
brush.js (2239B)
1 var brush = (function(){ 2 3 var brush = new Matrix (5, 5, function(x,y){ 4 var lex = new Lex (x,y) 5 lex.build() 6 return lex 7 }) 8 9 brush.modified = false 10 11 brush.mask = blit.circle 12 13 brush.generate = function(){ 14 brush.fill(brush) 15 brush.mask(brush) 16 } 17 18 brush.bind = function(){ 19 20 var last_point = [0,0] 21 var dragging = false 22 var erasing = false 23 24 brush.forEach(function(lex, x, y){ 25 26 if (lex.bound) return 27 lex.bound = true 28 29 var point = [x,y] 30 lex.span.addEventListener('contextmenu', function(e){ 31 e.preventDefault() 32 }) 33 lex.span.addEventListener('mousedown', function(e){ 34 e.preventDefault() 35 current_canvas = brush 36 brush.modified = true 37 dragging = true 38 erasing = (e.which == "3" || e.ctrlKey) 39 if (erasing) { 40 lex.clear() 41 } 42 else { 43 fillColor = brush.bg 44 lex.assign(brush) 45 } 46 brush.focus(x, y) 47 }) 48 lex.span.addEventListener('mousemove', function(e){ 49 e.preventDefault() 50 if (! dragging) { 51 return 52 } 53 erasing = (e.which == "3" || e.ctrlKey) 54 if (erasing) { 55 lex.clear() 56 } 57 else { 58 lex.assign(brush) 59 } 60 brush.focus(x, y) 61 }) 62 }) 63 window.addEventListener('mouseup', function(e){ 64 dragging = erasing = false 65 }) 66 } 67 68 brush.resize = function(w, h){ 69 w = this.w = clamp(w, this.min, this.max) 70 h = this.h = clamp(h, this.min, this.max) 71 brush.rebuild() 72 controls.brush_w.char = "" + w 73 controls.brush_w.build() 74 controls.brush_h.char = "" + h 75 controls.brush_h.build() 76 } 77 brush.size_add = function(w, h){ 78 brush.resize(brush.w + w, brush.h + h) 79 } 80 brush.expand = function(i){ 81 brush.size_add(i, i) 82 } 83 brush.contract = function(i){ 84 brush.size_add(-i, -i) 85 } 86 87 brush.load = function(lex){ 88 brush.char = lex.char 89 brush.fg = lex.fg 90 brush.bg = lex.bg 91 brush.opacity = 1 92 } 93 94 brush.min = 1 95 brush.max = 100 96 97 brush.char = " " 98 brush.fg = 0 99 brush.bg = 1 100 brush.opacity = 1 101 102 brush.draw_fg = true 103 brush.draw_bg = true 104 brush.draw_char = true 105 106 return brush 107 108 })()

