diff options
Diffstat (limited to 'js/matrix.js')
| -rw-r--r-- | js/matrix.js | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/js/matrix.js b/js/matrix.js index 08f5a79..95314b6 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -1,102 +1,102 @@ function Matrix (w,h,f){ - this.x = 0 - this.y = 0 - this.w = w - this.h = h - this.f = f - this.initialize() + this.x = 0 + this.y = 0 + this.w = w + this.h = h + this.f = f + this.initialize() } Matrix.prototype.initialize = function(){ - var w = this.w || 1, h = this.h || 1, f = this.f - var aa = new Array (h) - for (var y = 0; y < h; y++) { - aa[y] = new Array (w) - for (var x = 0; x < w; x++) { - aa[y][x] = f(x,y) - } - } - this.aa = aa + var w = this.w || 1, h = this.h || 1, f = this.f + var aa = new Array (h) + for (var y = 0; y < h; y++) { + aa[y] = new Array (w) + for (var x = 0; x < w; x++) { + aa[y][x] = f(x,y) + } + } + this.aa = aa } Matrix.prototype.rebuild = function (){ - this.demolish() - this.initialize() - this.append() - this.bind() - this.generate && this.generate() + this.demolish() + this.initialize() + this.append() + this.bind() + this.generate && this.generate() } Matrix.prototype.bind = function () {} Matrix.prototype.demolish = function (){ - this.forEach(function(lex){ - lex.demolish() - }) - while (this.rapper.firstChild) { + this.forEach(function(lex){ + lex.demolish() + }) + while (this.rapper.firstChild) { this.rapper.removeChild(this.rapper.firstChild); - } - this.aa.forEach(function(row){ - row.length = 0 - }) - this.aa.length = 0 + } + this.aa.forEach(function(row){ + row.length = 0 + }) + this.aa.length = 0 } Matrix.prototype.forEach = function(f){ - this.aa.forEach(function(row, y){ - row.forEach(function(lex, x){ - f(lex, x, y) - }) - }) + this.aa.forEach(function(row, y){ + row.forEach(function(lex, x){ + f(lex, x, y) + }) + }) } Matrix.prototype.focusLex = function(y,x){ - if (x < 0) { - y -= 1 - } - if (x > this.aa[0].length) { - y += 1 - } - this.aa[mod(y,this.h)][mod(x,this.w)].focus() + if (x < 0) { + y -= 1 + } + if (x > this.aa[0].length) { + y += 1 + } + this.aa[mod(y,this.h)][mod(x,this.w)].focus() } Matrix.prototype.clear = function(){ - this.forEach(function(lex,x,y){ lex.clear() }) + this.forEach(function(lex,x,y){ lex.clear() }) } Matrix.prototype.fill = function(fg, bg){ - this.fg = fg - this.bg = bg - this.forEach(function(lex,x,y){ - lex.fill(fg,bg) - lex.build() - }) + this.fg = fg + this.bg = bg + this.forEach(function(lex,x,y){ + lex.fill(fg,bg) + lex.build() + }) } Matrix.prototype.build = function(){ - this.forEach(function(lex,x,y){ - lex.build() - }) + this.forEach(function(lex,x,y){ + lex.build() + }) } Matrix.prototype.append = function(rapper){ - rapper = this.rapper = rapper || this.rapper + rapper = this.rapper = rapper || this.rapper this.aa.forEach(function(row, y){ - var div = document.createElement("div") - row.forEach(function(lex, x) { - div.appendChild(lex.span) - }) - rapper.appendChild( div ) - }) + var div = document.createElement("div") + row.forEach(function(lex, x) { + div.appendChild(lex.span) + }) + rapper.appendChild( div ) + }) } Matrix.prototype.region = function(w,h,x,y) { - w = w || 1 - h = h || 1 - x = x || 0 - y = y || 0 - var parent = this - var mat = new Matrix(w, h, function(x,y){ - return parent.aa[y][x] - }) - mat.f = this.f - return mat + w = w || 1 + h = h || 1 + x = x || 0 + y = y || 0 + var parent = this + var mat = new Matrix(w, h, function(x,y){ + return parent.aa[y][x] + }) + mat.f = this.f + return mat } Matrix.prototype.setCell = function(lex,x,y){ - this.aa[y] && this.aa[y][x] && this.aa[y][x].clone(lex) + this.aa[y] && this.aa[y][x] && this.aa[y][x].clone(lex) } Matrix.prototype.getCell = function(x,y){ - if (this.aa[y] && this.aa[y][x]) return this.aa[y][x] - else return null + if (this.aa[y] && this.aa[y][x]) return this.aa[y][x] + else return null } Matrix.prototype.resize = function(w,h){ var div, row, lex @@ -155,10 +155,10 @@ Matrix.prototype.ascii = function () { var lines = this.aa.map(function(row, y){ var last, line = "" row.forEach(function(lex, x) { - line += lex.ascii() - }) + line += lex.ascii() + }) return line // .replace(/\s+$/,"") - }) + }) var txt = lines.join("\n") return txt } @@ -166,22 +166,22 @@ Matrix.prototype.mirc = function () { var lines = this.aa.map(function(row, y){ var last, line = "" row.forEach(function(lex, x) { - if (lex.eq(last)) { - line += lex.sanitize() - } - else { - if (x > 0 && last) line += "\x03" - line += lex.mirc() - last = lex - } - }) - if (last && ! last.isClear()) { line += "\x03" } + if (lex.eq(last)) { + line += lex.sanitize() + } + else { + if (x > 0 && last) line += "\x03" + line += lex.mirc() + last = lex + } + }) + if (last && ! last.isClear()) { line += "\x03" } return line - }).filter(function(line){ return line.length > 0 }) - return lines.join("\n") + }).filter(function(line){ return line.length > 0 }) + return lines.join("\n") } Matrix.prototype.irssi = function(){ - var txt = this.mirc() + var txt = this.mirc() .replace(/\%/g, '%%') .replace(/\\/g, '\\x5C') .replace(/\"/g, '\\\"') @@ -194,23 +194,23 @@ Matrix.prototype.irssi = function(){ .replace(/\n/g, '\\n') .replace(/\x02/g, '\\x02') .replace(/\x03/g, '\\x03') - // console.log(txt.length) - var escaped_txt = "", kode - for (var i = 0; i < txt.length; i++) { - kode = txt.charCodeAt(i) - if (kode > 0x7f) { - kode = kode.toString(16) - switch (kode.length) { - case 2: - kode = "0" + kode - case 3: - kode = "0" + kode - } - escaped_txt += "\\u" + kode - } - else { - escaped_txt += txt[i] - } - } + // console.log(txt.length) + var escaped_txt = "", kode + for (var i = 0; i < txt.length; i++) { + kode = txt.charCodeAt(i) + if (kode > 0x7f) { + kode = kode.toString(16) + switch (kode.length) { + case 2: + kode = "0" + kode + case 3: + kode = "0" + kode + } + escaped_txt += "\\u" + kode + } + else { + escaped_txt += txt[i] + } + } return '/exec -out printf "' + escaped_txt + '"\n' } |
