-
Notifications
You must be signed in to change notification settings - Fork 2
/
rune_alphabet_typer.htm
107 lines (107 loc) · 2.98 KB
/
rune_alphabet_typer.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Rune Alphabet Typer</title>
<style>
body, html, textarea {
margin: 0;
padding: 0;
}
img {
display: none;
}
#input, canvas {
display: inline-block;
width: -webkit-fill-available;
height: -webkit-fill-available;
}
textarea {
width: 600px;
height: 600px;
resize: none;
padding: 10px;
background: rgb(202, 202, 202);
}
.wrapper {
display: grid;
grid-template-columns: 1fr 3fr;
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div class="wrapper">
<textarea id="input" placeholder="Type text here"></textarea>
<canvas id="output" stlye="image-rendering: pixelated;"></canvas>
</div>
<img id="rune_alphabet" src="rune_alphabet_sprites.png">
<script>
const input = document.getElementById('input');
const output = document.getElementById('output');
const rune_alphabet = document.getElementById('rune_alphabet');
const ctx = output.getContext('2d');
const offsets = {
'a': { x: 0, y: 0 },
'b': { x: 6, y: 0 },
'c': { x: 12, y: 0 },
'd': { x: 18, y: 0 },
'e': { x: 24, y: 0 },
'f': { x: 30, y: 0 },
'g': { x: 36, y: 0 },
'h': { x: 42, y: 0 },
'i': { x: 48, y: 0 },
'k': { x: 0, y: 6 },
'l': { x: 6, y: 6 },
'm': { x: 12, y: 6 },
'n': { x: 18, y: 6 },
'o': { x: 24, y: 6 },
'p': { x: 30, y: 6 },
'r': { x: 36, y: 6 },
's': { x: 42, y: 6 },
't': { x: 48, y: 6 },
'u': { x: 0, y: 12 },
'v': { x: 6, y: 12 },
'w': { x: 12, y: 12 },
'y': { x: 18, y: 12 },
'z': { x: 24, y: 12 },
',': { x: 30, y: 12 },
'.': { x: 36, y: 12 },
' ': { x: 666, y: 666 },
};
const canvas_width = output.width = parseInt(getComputedStyle(output).width);
const canvas_height = output.height = parseInt(getComputedStyle(output).height);
const zoom = 4;
const padding = 10;
drawRuneText('');
function drawRuneText(text) {
ctx.imageSmoothingEnabled = false;
ctx.fillStyle = 'black';
ctx.beginPath();
ctx.rect(0, 0, canvas_width, canvas_height);
ctx.fill();
let x = 0, y = 0;
Array.from(text).forEach(letter => {
letter = letter.toLowerCase();
if(letter == '\n') {
y++;
x = 0;
} else if(offsets[letter] != null) {
const offset = offsets[letter];
// (img,sx,sy,swidth,sheight,x,y,width,height);
ctx.drawImage(rune_alphabet, offset.x, offset.y, 6, 6, x*5*zoom+padding, y*6*zoom+padding, 6*zoom, 6*zoom);
console.log(letter)
x++;
}
});
}
input.addEventListener('keyup', ev => {
const text = ev.target.value;
drawRuneText(text);
});
</script>
</body>
</html>