-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx3x3.js
51 lines (42 loc) · 2.05 KB
/
x3x3.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
/*x3x3-0.3.1;(c)2018 - Mntn(r) <https://mn.tn/> c/o Benjamin Lips <g--[AT]--mn.tn>;MIT-Licensed <https://mit-license.org/>;
Usage:
x3x3.txt('hello world.'[,mask_char='#']); //valid chars: a-z 0-9 |_=+*-.,:'/[](){}<>"$€°\
x3x3.svg('hello world.'[,box_size=10,color='black']);
Demos:
https://rawgit.com/mntn-dev/x3x3/master/demo.htm
https://rawgit.com/mntn-dev/x3x3/master/demo2.htm
*/
;var x3x3={
svg:function(o,d,f){
if(isNaN(d))d=10;
if(!(o=x3x3.txt(o)))return;
o=o.split('\n');
var _='',c,l,j,h,w;
c=Math.random().toString(36).substr(2,3);
for(l=0;l<3;l++)for(j=0;j<o[1].length-1;j++)if(o[l+1][j]!=' ')_+='<rect class="_'+c+'" x="'+(j*d)+'" y="'+(l*d)+'"/>';
return ('<svg width="'+(w=((o[1].length-1)*d))+'" height="'+(h=(d*3))+'" viewBox="0 0 '+w+' '+h+
'" xmlns="http://www.w3.org/2000/svg" shape-rendering="crispEdges"><style type="text/css">'+
'<![CDATA[._'+c+'{height:'+d+';width:'+d+';fill:'+(f?f:'#000')+';}]]></style>'+_+'</svg>');
},
txt:function(o,m=!1){
var
_='a ^ ^^^^ ^b^^ ^^^^^^c^^^^ ^^^d^^ ^ ^^^ e^^^^^ ^^^f^^^^^ ^ g^^ ^ ^^^^h^ ^^^^^ ^'+
'i^^^ ^ ^^^j ^ ^^^ k^ ^^^ ^ ^l^ ^ ^^^m^^^^^^^ ^n^^^^ ^^ ^o^^^^ ^^^^p^^^^^^^ '+
'q^^^^^^ ^r^^^^ ^ s ^^ ^ ^^ t^^^ ^ ^ u^ ^^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