Improved efficiency of blocktype

This commit is contained in:
walterhiggins 2013-01-21 22:18:47 +00:00
parent d57c5868ee
commit a9f03f7d7c

View file

@ -2,7 +2,8 @@ load(__folder + "drone.js");
(function(){
var bitmap = {
var bitmaps = {
raw: {
'0':' ### '+
' # # '+
' # # '+
@ -278,7 +279,23 @@ load(__folder + "drone.js");
' '+
' '+
' '
},
computed: {}
};
/*
wph 20130121 compute the width, and x,y coords of pixels ahead of time
*/
for (var c in bitmaps.raw){
var bits = bitmaps.raw[c];
var width = bits.length/5;
var bmInfo = {"width": width,"pixels":[]}
bitmaps.computed[c] = bmInfo;
for (var j = 0; j < bits.length; j++){
if (bits.charAt(j) != ' '){
bmInfo.pixels.push([j%width,Math.ceil(j/width)]);
}
}
}
Drone.extend('blocktype', function(message,fg,bg){
this.chkpt('blocktext');
@ -287,25 +304,22 @@ load(__folder + "drone.js");
for (var h = 0;h < lineCount; h++) {
var line = lines[h];
line = line.toLowerCase().replace(/[^0-9a-z \.\-\+\/\;\'\:\!]/g,"");
print ("lineCount=" + lineCount);
this.up(7*(lineCount-(h+1)));
for (var i =0;i < line.length; i++) {
var ch = line.charAt(i)
var bits = bitmap[ch];
var bits = bitmaps.computed[ch];
if (typeof bits == "undefined"){
bits = bitmap[' '];
bits = bitmaps.computed[' '];
}
var charWidth = bits.length/5;
var charWidth = bits.width;
if (typeof bg != "undefined")
this.box(bg,charWidth,7,1);
for (var j = 0;j < bits.length;j++){
for (var j = 0;j < bits.pixels.length;j++){
this.chkpt('btbl');
if (bits.charAt(j) != ' '){
var x = j % charWidth;
var y = Math.ceil(j/charWidth);
var x = bits.pixels[j][0];
var y = bits.pixels[j][1];
this.up(6-y).right(x).box(fg);
}
this.move('btbl');
}
this.right(charWidth-1);