var blit = (function(){ var blit = {} blit.and = blit.atop = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell && lex.opacity > 0) { cell.assign(lex) } }) } blit.or = blit.under = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell && cell.opacity == 0) { cell.assign(lex) } }) } // copy the region of A beginning at x,y into B blit.copy_from = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell) { lex.assign(cell) } }) } blit.copy_to = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell) { cell.assign(lex) } }) } blit.invert = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) if (cell && lex.opacity > 0) { cell.fg = get_inverse(cell.fg) cell.bg = get_inverse(cell.bg) } }) } blit.circle = function(A, lex){ var hw = brush.w/2|0, hh = brush.h/2|0 A.forEach(function(lex,x,y) { var len = Math.sqrt(Math.pow(x-hw,2)+Math.pow(y-hh,2)) if (len > Math.abs(hw)) { lex.clear() } }) } blit.cross = function(A, lex){ A.forEach(function(lex,x,y) { if ((x+y)%2) { lex.clear() } }) } return blit })()