-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
111 lines (91 loc) · 3.21 KB
/
index.html
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
<html>
<head>
<title>Learn to Type</title>
<style>
body{
background-color: skyblue;
display: flex;
justify-content: space-evenly;
align-items: center;
flex-direction: column;
height: 100vh;
margin: 0;
font-family: "Arial";
}
input {
border-radius: 3px;
padding: 5px;
font-size: 20px;
opacity: 0.1;
}
span {
font-size: 42px;
color: transparent;
-webkit-text-stroke: 2px;
-webkit-text-stroke-color: black;
font-family: "Arial Heavy";
transition: 0.5s;
display: inline-block;
}
span.space {
margin: 0 6px;
}
span.success {
color: green;
animation: 0.5s pop;
}
@keyframes pop {
from {
transform: scale(1);
}
50% {
transform: scale(1.25);
}
to {
transform: scale(1);
}
}
</style>
<script src="https://tonejs.github.io/build/Tone.js"></script>
</head>
<body>
<div id="text"></div>
<input id="in" type="text" autofocus>
<script>
var text = document.getElementById('text');
var string = 'The quick brown fox jumps over the lazy dog.'.split('');
for (let char of string) {
let span = document.createElement('span');
if (char == ' ') span.classList.add('space');
span.textContent = char;
text.append(span);
}
const alpha = Array.from(Array(26)).map((e, i) => i + 65);
const alphabet = alpha.map((x) => String.fromCharCode(x));
const scale = alphabet.slice(0, 7);
console.log(scale);
let alphatone = new Map();
for (let [i, letter] of alphabet.entries()) {
alphatone.set(letter, scale[i % 7] + (Math.floor(i / 7) + 3));
}
console.log(alphatone);
var input = document.getElementById('in');
input.onkeypress = function(e) {
let match = text.textContent.match(new RegExp(input.value + e.key));
const synth = new Tone.Synth().toDestination();
const now = Tone.now()
// trigger the attack immediately
synth.triggerAttack(120 + 5 * alphabet.indexOf(e.key.toUpperCase()), now)
// wait one second before triggering the release
synth.triggerRelease(now + 0.25)
for (let [i, char] of text.querySelectorAll('span').entries()) {
if (i < match[0].length) {
char.classList.add('success');
} else {
break;
}
}
}
</script>
</body>
</html>