-
Notifications
You must be signed in to change notification settings - Fork 2
/
writer.js
87 lines (70 loc) · 1.75 KB
/
writer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function textwriter()
{
this.write=function(id, text, crlf)
{
var domtext="<span style=\"white-space:nowrap;\">";
for (var i=0; i<text.length; i++)
{
var offs=(text.charCodeAt(i)-32);
// Add crlf when in string
if (offs==(13-32))
domtext+="<br/>";
// Don't try to draw characters outside our font set
if ((offs<0) || (offs>94))
continue;
// Handle spaces
if (offs==0)
domtext+="</span>";
// Add character wrapper
domtext+="<div class=\"alphablock\">";
// Add "pixels"
var p=0;
for (var j=0; j<4; j++)
{
var dual=font_8bit[(offs*4)+j]||0;
for (var k=0; k<8; k++)
{
if (dual&(1<<(8-k)))
domtext+="<div class=\"block filled\"></div>";
else
domtext+="<div class=\"block\"></div>";
// Add line break between character rows
p++;
if (p==4)
{
domtext+="<br/>";
p=0;
}
}
}
// Close wrapper
domtext+="</div>";
// Handle spaces
if (offs==0)
domtext+="<span style=\"white-space:nowrap;\">";
}
domtext+="</span>";
if ((crlf==undefined) || (crlf!=false))
domtext+="<br/>";
// Pass domtext to the DOM for rendering
document.getElementById(id).innerHTML+=domtext;
};
this.text="";
this.pos=0;
this.id="wrapper";
this.typechar=function()
{
if (this.pos<this.text.length)
{
this.write(this.id, this.text.charAt(this.pos), false);
this.pos++;
}
};
this.typewrite=function(id, text)
{
document.getElementById(id).innerHTML="";
this.id=id;
this.pos=0;
this.text=text+String.fromCharCode(13);
};
}