Initial commit

This commit is contained in:
Ricardo Mazeto 2020-01-15 15:15:16 -07:00
commit 28b66ea833
1 changed files with 394 additions and 0 deletions

394
canvasterm.js Normal file
View File

@ -0,0 +1,394 @@
var fbm = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,16,16,16,16,16,16,16,0,16,16,0,0,0,0,
0,0,36,36,36,0,0,0,0,0,0,0,0,0,0,0,
0,0,36,36,36,126,36,36,126,36,36,36,0,0,0,0,
0,0,16,16,124,146,144,124,18,18,146,124,16,16,0,0,
0,0,100,148,104,8,16,16,32,44,82,76,0,0,0,0,
0,0,24,36,36,24,48,74,68,68,68,58,0,0,0,0,
0,0,16,16,16,0,0,0,0,0,0,0,0,0,0,0,
0,0,8,16,32,32,32,32,32,32,16,8,0,0,0,0,
0,0,16,8,4,4,4,4,4,4,8,16,0,0,0,0,
0,0,0,0,0,36,24,126,24,36,0,0,0,0,0,0,
0,0,0,0,0,16,16,124,16,16,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,16,16,32,0,0,0,
0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,16,16,0,0,0,0,
0,0,4,4,8,8,16,16,32,32,64,64,0,0,0,0,
0,0,60,66,66,70,74,82,98,66,66,60,0,0,0,0,
0,0,16,48,80,16,16,16,16,16,16,124,0,0,0,0,
0,0,60,66,66,2,4,8,16,32,64,126,0,0,0,0,
0,0,60,66,66,2,28,2,2,66,66,60,0,0,0,0,
0,0,2,6,10,18,34,66,126,2,2,2,0,0,0,0,
0,0,126,64,64,64,124,2,2,2,66,60,0,0,0,0,
0,0,28,32,64,64,124,66,66,66,66,60,0,0,0,0,
0,0,126,2,2,4,4,8,8,16,16,16,0,0,0,0,
0,0,60,66,66,66,60,66,66,66,66,60,0,0,0,0,
0,0,60,66,66,66,66,62,2,2,4,56,0,0,0,0,
0,0,0,0,0,16,16,0,0,0,16,16,0,0,0,0,
0,0,0,0,0,16,16,0,0,0,16,16,32,0,0,0,
0,0,0,4,8,16,32,64,32,16,8,4,0,0,0,0,
0,0,0,0,0,0,126,0,0,126,0,0,0,0,0,0,
0,0,0,64,32,16,8,4,8,16,32,64,0,0,0,0,
0,0,60,66,66,2,4,8,8,0,8,8,0,0,0,0,
0,0,124,130,190,162,162,162,166,154,128,126,0,0,0,0,
0,0,0,56,68,68,68,68,124,68,68,68,68,0,0,0,
0,0,124,66,66,66,124,66,66,66,66,124,0,0,0,0,
0,0,60,66,66,64,64,64,64,66,66,60,0,0,0,0,
0,0,120,68,66,66,66,66,66,66,68,120,0,0,0,0,
0,0,126,64,64,64,120,64,64,64,64,126,0,0,0,0,
0,0,126,64,64,64,120,64,64,64,64,64,0,0,0,0,
0,0,60,66,66,64,64,78,66,66,66,60,0,0,0,0,
0,0,66,66,66,66,126,66,66,66,66,66,0,0,0,0,
0,0,56,16,16,16,16,16,16,16,16,56,0,0,0,0,
0,0,14,4,4,4,4,4,4,68,68,56,0,0,0,0,
0,0,66,68,72,80,96,96,80,72,68,66,0,0,0,0,
0,0,64,64,64,64,64,64,64,64,64,126,0,0,0,0,
0,0,130,198,170,146,146,130,130,130,130,130,0,0,0,0,
0,0,130,130,194,162,146,138,134,130,130,130,0,0,0,0,
0,0,60,66,66,66,66,66,66,66,66,66,60,0,0,0,
0,0,124,66,66,66,66,124,64,64,64,64,0,0,0,0,
0,0,60,66,66,66,66,66,66,66,66,74,60,2,0,0,
0,0,124,66,66,66,66,124,80,72,68,66,0,0,0,0,
0,0,60,66,64,64,60,2,2,66,66,60,0,0,0,0,
0,0,254,16,16,16,16,16,16,16,16,16,0,0,0,0,
0,0,66,66,66,66,66,66,66,66,66,60,0,0,0,0,
0,0,66,66,66,66,66,36,36,36,24,24,0,0,0,0,
0,0,130,130,130,130,130,146,146,170,198,130,0,0,0,0,
0,0,66,66,36,36,24,24,36,36,66,66,0,0,0,0,
0,0,130,130,68,68,40,16,16,16,16,16,0,0,0,0,
0,0,126,2,2,4,8,16,32,64,64,126,0,0,0,0,
0,0,56,32,32,32,32,32,32,32,32,56,0,0,0,0,
0,0,64,64,32,32,16,16,8,8,4,4,0,0,0,0,
0,0,28,4,4,4,4,4,4,4,4,28,0,0,0,0,
0,16,40,68,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,126,0,0,
32,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,60,2,62,66,66,66,62,0,0,0,0,
0,0,64,64,64,124,66,66,66,66,66,124,0,0,0,0,
0,0,0,0,0,60,66,64,64,64,66,60,0,0,0,0,
0,0,2,2,2,62,66,66,66,66,66,62,0,0,0,0,
0,0,0,0,0,60,66,66,126,64,64,62,0,0,0,0,
0,0,14,16,16,124,16,16,16,16,16,16,0,0,0,0,
0,0,0,0,0,62,66,66,66,66,66,62,2,2,60,0,
0,0,64,64,64,124,66,66,66,66,66,66,0,0,0,0,
0,0,16,16,0,48,16,16,16,16,16,56,0,0,0,0,
0,0,8,8,0,24,8,8,8,8,8,8,72,48,0,0,
0,0,32,32,32,34,36,40,48,40,36,34,0,0,0,0,
0,0,24,8,8,8,8,8,8,8,8,28,0,0,0,0,
0,0,0,0,0,252,146,146,146,146,146,146,0,0,0,0,
0,0,0,0,0,124,66,66,66,66,66,66,0,0,0,0,
0,0,0,0,0,60,66,66,66,66,66,60,0,0,0,0,
0,0,0,0,0,124,66,66,66,66,66,124,64,64,64,0,
0,0,0,0,0,62,66,66,66,66,66,62,2,2,2,0,
0,0,0,0,0,94,96,64,64,64,64,64,0,0,0,0,
0,0,0,0,0,62,64,64,60,2,2,124,0,0,0,0,
0,0,16,16,16,126,16,16,16,16,16,14,0,0,0,0,
0,0,0,0,0,66,66,66,66,66,66,62,0,0,0,0,
0,0,0,0,0,66,66,66,36,36,24,24,0,0,0,0,
0,0,0,0,0,130,130,146,146,146,146,108,0,0,0,0,
0,0,0,0,0,66,66,36,24,36,66,66,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0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
'use strict';
/* fb = framebuffer
fbw = framebuffer width,
fbh = framebuffer height,
fbs = framebuffer scale,
fbar = frame buffer aspect ratio,
cw = character width,
ch = character height,
hz = hertz,
phz = previous hertz,
cols = colums,
rows = rows,
chrbuf = character buffer,
colbuf = colors buffer,
charum = character update map,
cl = color loop,
pt = printable tags,
CS = color scheme */
var fbw, fbh, fbs, fbar, hz=4, vsync,
cw=8, ch=16, fg=0, bg=7, cols, rows,
cs=[], i=0, j=0, cl=0, v=Math.floor,
pt=["H1","H2","H3","H4","H5","H6","P","A"],
fb = document.getElementsByTagName("canvas")[0]
.getContext("2d"),
CS=[ 0,0,0,160,0,0,32,128,64,192,128,0,0,64,
128,96,32,128,0,128,128,160,160,128,96,
96,64,224,32,64,128,192,64,224,192,0,64,
96,192,160,64,128,96,192,128,224,224,192 ];
var setfg = (c) => fg = c;
var setbg = (c) => bg = c;
var n = (n) => String(Number(CS[n]));
/* clears the framebuffer */
var fbclear = () => {
fb.fillStyle = cs[bg];
fb.fillRect(0, 0, fbw, fbh);
};
/* writes a character */
var putc = (c, x, y) => {
var i=0,j=1,w=0;
fb.fillStyle=cs[bg];
fb.fillRect(v(x*(fbw/cols)),v(y*(fbh/rows)),cw,ch);
fb.fillStyle=cs[fg];
while(i<16){
j=0x80,w=0;
while(j)
(fbm[c*16+i]&j)
?(fb.fillRect(
v(x*(fbw/cols)+w),
v(y*(fbh/rows)+i),
fbs,fbs),
j=j>>1,w++)
:(j=j>>1,w++);
i++;
};
};
/* returns the numerical code of the first character
of a given string */
var hex = (s) => s.charCodeAt(0);
/* write string */
var puts = (str, x, y) => {
var l=str.length;
var i=0;
while(i<l)
y = (x=x<cols-1?x+1:0) ? y : ++y%(rows-1),
putc(hex(str[i++]),x,y);
};
var charcode = (n) => String.fromCharCode(n);
var draw = () => {
var x=0,y=0;
var tst = (i) =>
(i<128)?(setfg((v(i/8)%16)),
setbg(v(cl++/8)%11),
puts(charcode(i),i%8+1,v(((i++)-32)/8)+1),
tst(i))
:(i++);
tst(32);
setfg(7);setbg(0);
};
/* set terminal refresh rate */
var setrr = (n) => {
clearInterval(vsync);
vsync = setInterval(draw,1000/n);
};
var resize = () => {
fbh = fb.canvas.height = window.innerHeight;
fbw = fb.canvas.width = window.innerWidth;
fbar= v(fbw/fbh)>1?1:0;
cols = v(fbw/8);
rows = v(fbh/16);
fbs=1;
};
var bro = (n) => n.nextElementSibling;/*bro*/
var kid = (n) => n.childNodes[0];/*kid*/
var nkids = (n) => n.childNodes.length;/*#ofkids*/
var uncle = (n) => n.parentNode;/*uncle*/
var inc = (s) => { s[s.length-1]++; s;};/*increment*/
/* Traverses the node tree n calling f on every element. */
var dw = (n,f,s) => {
(n)
? (nkids(n))
?(s.push(0),dw(kid(n),f,s))
:(f(n),(bro(n)
?(inc(s),dw(bro(n),f,s))
:(s.pop(),inc(s),dw(uncle(n),f,s))))
:(0)
};
var setpointer = (e) => console.log(e.x, e.y);
(() => {
/* fill the cs, color scheme, array */
while(i<16)
cs[i++]="rgb("+n(j++)+","+n(j++)+","+n(j++)+")";
/* fill the fbm Array Buffer
i=0;
while(i<(0xff*0x10))
fbm.setUint8(i,);*/
/* update the refresh rate */
setrr(hz);
/* show the screen */
resize();
/* resize the canvas when the window is resized */
window.onresize = resize;
/* draws negative cell on pointer position */
window.onpointermove = setpointer;
})();