main.js
1.31 KB
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
$(function() {
var socket = io();
var scores = [];
var list = $('#scores ol');
socket.emit('getScores');
socket.on('scores', function(newScores) {
scores = newScores;
redrawScores();
});
socket.on('newScore', function addScore(obj) {
scores.push(obj);
redrawScores();
});
socket.on('msg', function(msg) {
$('#sub').text(msg);
});
function redrawScores() {
var sortable = [];
scores.sort(function(b, a) {return a.score - b.score})
var list = $('#scores ol');
list.empty();
for (i in scores) {
if (i < 15) {
var obj = scores[i];
list.append($('<li>').text(obj.score + ' - ' + obj.name));
}
}
}
function rainbowColor(el) {
var hue = Math.floor(Math.random()*360);
el.css('filter', 'hue-rotate('+hue+'deg)');
}
var logo = $('#logo');
setInterval(function rainbowLogo() {
rainbowColor(logo);
}, 500);
(function anim() {
var now = Date.now()/1000;
// Logo
var scale = (Math.sin(now*5) + 1)/5 + 0.7;
var rot = Math.sin(now*10)/10;
logo.css('transform', 'rotate(' + rot + 'rad) scale(' + scale + ')');
requestAnimationFrame(anim);
})();
});