-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
251 lines (237 loc) · 7.34 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<title>Ratatat</title>
<link rel="stylesheet" type="text/css" href="Ratatat.css" />
<link rel="icon" href="favicon.ico" />
<!-- Load font -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Hammersmith+One&display=swap"
rel="stylesheet"
/>
<!-- load paper.js animation library -->
<script type="text/javascript" src="paper-full.js"></script>
<!-- load howler.js audio library -->
<script src="https://cdn.jsdelivr.net/npm/howler@2.1.3/dist/howler.min.js"></script>
<!-- paper.js code -->
<script type="text/paperscript" canvas="musicCanvas">
// define an object to contain colour and sound data that is unique to each keyboard key
var keyData = {
q: {
sound: new Howl({
src: ['sounds/bubbles.mp3']
}),
color: '#1abc9c'
},
w: {
sound: new Howl({
src: ['sounds/clay.mp3']
}),
color: '#2ecc71'
},
e: {
sound: new Howl({
src: ['sounds/confetti.mp3']
}),
color: '#3498db'
},
r: {
sound: new Howl({
src: ['sounds/corona.mp3']
}),
color: '#9b59b6'
},
t: {
sound: new Howl({
src: ['sounds/dotted-spiral.mp3']
}),
color: '#34495e'
},
y: {
sound: new Howl({
src: ['sounds/flash-1.mp3']
}),
color: '#16a085'
},
u: {
sound: new Howl({
src: ['sounds/flash-2.mp3']
}),
color: '#27ae60'
},
i: {
sound: new Howl({
src: ['sounds/flash-3.mp3']
}),
color: '#2980b9'
},
o: {
sound: new Howl({
src: ['sounds/glimmer.mp3']
}),
color: '#8e44ad'
},
p: {
sound: new Howl({
src: ['sounds/moon.mp3']
}),
color: '#2c3e50'
},
a: {
sound: new Howl({
src: ['sounds/pinwheel.mp3']
}),
color: '#f1c40f'
},
s: {
sound: new Howl({
src: ['sounds/piston-1.mp3']
}),
color: '#e67e22'
},
d: {
sound: new Howl({
src: ['sounds/piston-2.mp3']
}),
color: '#e74c3c'
},
f: {
sound: new Howl({
src: ['sounds/prism-1.mp3']
}),
color: '#95a5a6'
},
g: {
sound: new Howl({
src: ['sounds/prism-2.mp3']
}),
color: '#f39c12'
},
h: {
sound: new Howl({
src: ['sounds/prism-3.mp3']
}),
color: '#d35400'
},
j: {
sound: new Howl({
src: ['sounds/splits.mp3']
}),
color: '#1abc9c'
},
k: {
sound: new Howl({
src: ['sounds/squiggle.mp3']
}),
color: '#2ecc71'
},
l: {
sound: new Howl({
src: ['sounds/strike.mp3']
}),
color: '#3498db'
},
z: {
sound: new Howl({
src: ['sounds/suspension.mp3']
}),
color: '#9b59b6'
},
x: {
sound: new Howl({
src: ['sounds/timer.mp3']
}),
color: '#34495e'
},
c: {
sound: new Howl({
src: ['sounds/ufo.mp3']
}),
color: '#16a085'
},
v: {
sound: new Howl({
src: ['sounds/veil.mp3']
}),
color: '#27ae60'
},
b: {
sound: new Howl({
src: ['sounds/wipe.mp3']
}),
color: '#2980b9'
},
n: {
sound: new Howl({
src: ['sounds/zig-zag.mp3']
}),
color: '#8e44ad'
},
m: {
sound: new Howl({
src: ['sounds/moon.mp3']
}),
color: '#2c3e50'
}
};
// create an empty array that will contain all the circles we create
var circles = [];
// now set what happens when we push a key:
function onKeyDown(event) {
if(keyData[event.key]){
// the variable maxScreen is the dimensions of the visible screen window
var maxScreen = new Point(view.size.width, view.size.height);
// the variable randomPoint is a random genterated number between 0 and 1 - coordinates between (0,0) and (1,1)
var randomPoint = Point.random();
// the variable point is the point where the new circle will be drawn. It will be a random location but within the visible screen/window dimensions
var point = maxScreen * randomPoint;
// draw a new circle in a random location in the visible window/canvas. Fill it with the correct colour from keyData. Then add (push) it to the circles array
var newCircle = new Path.Circle(point, 500);
newCircle.fillColor = keyData[event.key].color;
keyData[event.key].sound.play();
circles.push(newCircle);
}
}
// animate all the the circles - for every frame of the animation loop through all the circles in the circles array and add one to the hue and scale it by 0.9 (shrink it)
function onFrame(event){
for(var i = 0; i<circles.length; i++){
circles[i].fillColor.hue +=1;
circles[i].scale (0.95);
if(circles[i].area < 1){
circles[i].remove(); // remove small circles from the canvas
circles.splice(i, 1); // remove small circles from the array
console.log(circles);
}
}
}
</script>
</head>
<body>
<header>
<div id="instructions">
<p>Press any of the A-Z keys</p>
<p>Sound on!</p>
</div>
</header>
<canvas id="musicCanvas" resize="true"></canvas>
<footer>
<p>
Created by
<a href="https://github.com/MakeItBack/Ratatat" target="__blank"
>MakeItBack</a
>
</p>
</footer>
<!--Messgae to appears on touchscreen devices (no keyboard) -->
<div id="touchscreen-info">
<p>
Sorry!<br />This app needs a keyboard.<br />Please try again from
your PC.
</p>
</div>
</body>
</html>