-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhoekschrift.js
116 lines (101 loc) · 3.43 KB
/
hoekschrift.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;
(function($) {
var SIZE = 30;
var D0 = SIZE * 0.2;
var DL = SIZE - D0;
var DM = SIZE /2;
function encrypt($cnv, txt) {
var lines = wrappit(txt, $cnv.width());
var gc = $cnv.get(0).getContext("2d");
gc.clearRect( 0, 0, $cnv.width(), $cnv.height());
gc.lineWidth = 3;
gc.lineCap = "square";
for (var r = 0; r < lines.length; r++) {
var line = lines[r];
for (var c = 0; c < line.length; c++) {
drawChar(gc, c*SIZE, r*2*SIZE, line.charAt(c));
}
}
}
function wrappit (src, w) {
w = w || 80 * SIZE;
var positions = Math.floor(w/SIZE);
var tgt = new Array();
var line = "";
var words = src.split(' ');
for(var i = 0; i < words.length; i++) {
word = words[i];
var wordlines = word.split('\n');
for (var j=0; j < wordlines.length; j++) {
var part = wordlines[j];
if (line.length + part.length < positions) {
line += (line.length ? " " : "") + part;
} else {
if (line.length) tgt[tgt.length] = line;
line = part;
}
if (j+1 < wordlines.length) {
if (line.length) tgt[tgt.length] = line;
line = "";
}
}
}
if (line.length) tgt[tgt.length] = line;
return tgt;
}
var ACODE = "a".charCodeAt(0);
function drawChar(gc, x, y, t) {
t = t.toLowerCase();
var code = t.charCodeAt(0) - ACODE;
if (code < 0 || code > 25) return; // just leave blank
gc.save();
try {
gc.translate(x,y);
drawCode(gc, code);
} finally {
gc.restore();
}
}
function drawCode(gc, code) {
if (code < 18) {
var dot = Math.floor(code /9);
code = code %9
drawHash(gc, code, dot);
} else {
code = code -18;
var dot = Math.floor(code /4);
code = code % 4;
drawIeks(gc, code, dot);
}
}
function drawHash(gc, code, dot){
var r = Math.floor(code /3);
var c = code %3;
gc.beginPath();
gc.moveTo(D0,D0);
r==0 ? gc.moveTo(DL,D0) : gc.lineTo(DL,D0);
c==2 ? gc.moveTo(DL,DL) : gc.lineTo(DL,DL);
r==2 ? gc.moveTo(D0,DL) : gc.lineTo(D0,DL);
c==0 ? gc.moveTo(D0,D0) : gc.lineTo(D0,D0);
gc.moveTo(DM,DM);
if (dot) gc.arc(DM, DM, 1, 0, Math.PI *2, true);
gc.stroke();
}
var IEKS = [
[{x:D0,y:D0}, {x:DM,y:DL}, {x:DL,y:D0}, {x:DM,y:D0}],
[{x:D0,y:D0}, {x:DL,y:DM}, {x:D0,y:DL}, {x:D0,y:DM}],
[{x:DL,y:D0}, {x:D0,y:DM}, {x:DL,y:DL}, {x:DL,y:DM}],
[{x:D0,y:DL}, {x:DM,y:D0}, {x:DL,y:DL}, {x:DM,y:DL}]
];
function drawIeks(gc, code, dot){
var ieks = IEKS[code];
gc.beginPath();
gc.moveTo( ieks[0].x, ieks[0].y);
gc.lineTo( ieks[1].x, ieks[1].y);
gc.lineTo( ieks[2].x, ieks[2].y);
gc.moveTo( ieks[3].x, ieks[3].y);
if (dot) gc.arc(ieks[3].x, ieks[3].y, 1, 0, Math.PI *2, true);
gc.stroke();
}
$.extend({"hoekschrift": encrypt});
})(jQuery);