-
Notifications
You must be signed in to change notification settings - Fork 16
/
screentunes.js
73 lines (66 loc) · 1.82 KB
/
screentunes.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
(function() {
var canvas;
var ctx;
var start = null;
var t = null;
var AnimationFrame = (function() {
var FPS = 16.6666666667; // 1000 / 60 = Frames Per Second
var RAF = window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.msRequestAnimationFrame
|| window.oRequestAnimationFrame
|| function(a) { window.setTimeout(a, FPS); }
var CAF = window.cancelAnimationFrame
|| window.webkitCancelAnimationFrame
|| window.mozCancelAnimationFrame
|| window.msCancelAnimationFrame
|| window.oCancelAnimationFrame
|| function(a) { window.clearTimeout(a); }
return {
request: function(a) {
RAF(a);
},
cancel: function(a) {
CAF(a);
}
}
})();
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
/* $("#canvas").css("width", w + "px");
$("#canvas").css("height", h + "px"); */
/* render(); */
}
function bar(y, height) {
ctx.fillRect(0,y,canvas.width,height);
}
function bars(spacing, height) {
ctx.fillStyle = "rgb(0,0,0)";
var y = 0;
var maxy = canvas.height;
while(y < maxy) {
bar(y,height);
y += spacing + height;
}
}
function render() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
var magic = 5 + (Math.sin(t / 2000)+1)*7;
bars(magic, magic);
}
function frame(timestamp) {
if (start === null) start = timestamp;
t = timestamp - start;
render();
AnimationFrame.request(frame);
}
$(document).ready(function() {
canvas = document.getElementById("main");
ctx = canvas.getContext("2d");
$(window).bind("resize", resize);
resize();
AnimationFrame.request(frame);
});
})();