-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyrhythm.html
102 lines (83 loc) · 1.92 KB
/
polyrhythm.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
<!doctype html>
<html>
<head>
<style type='text/css'>
canvas {
border: 1px solid #aaa;
cursor: none;
}
</style>
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
<script type="text/javascript">
var context;
var x = 0;
var y = 0;
var width = 400;
var height = 400;
var timings = [];
var boxes = [];
function draw() {
}
function clearScreen () {
context.clearRect(0, 0, width, height);
context.fillStyle = "black";
context.fillRect(0,0,width,height);
}
function drawRed() {
context.fillStyle = "red";
context.fillRect(0,0,20,20);
}
function Box(speed, color, x, y) {
this.speed = speed;
this.x = x;
this.y = y;
this.color = color;
this.tick = function() {
context.fillStyle = "white";
context.fillRect(this.x, this.y,30,30);
this.x += this.speed;
context.fillStyle = this.color;
context.fillRect(this.x, this.y,30,30);
if (this.x > 200) {
context.fillStyle = "white";
context.fillRect(this.x, this.y,30,30);
this.x = 0;
}
}
}
function update() {
for (var i = 0; i < boxes.length; i++) {
var b = boxes[i];
b.tick();
}
context.fillStyle = "green";
context.fillRect(0,0,10,140);
}
$(document).ready(function() {
var address = location.href;
var urlComponents = address.split('?');
var urlTimings = urlComponents[1].split('=')[1].split(',');
for (var i = 0; i < urlTimings.length; i++) {
var timing = parseInt(urlTimings[i]);
timings.push(timing);
}
console.log(location.href);
//send to server?
var canvas = $('#canvas');
context = canvas.get(0).getContext('2d');
var b1 = new Box(timings[0], "red",0,0);
var b2 = new Box(timings[1], "blue", 0, 70);
var colors = ["red", "blue"];
for (var i = 0; i < timings.length; i++) {
var b = new Box(timings[i], colors[i],0,70 * i);
boxes.push(b);
}
// boxes.push(b1);
// boxes.push(b2);
setInterval(update, 1000/10);
});
</script>
</head>
<body>
<canvas id='canvas' width=500 height=500></canvas>
</body>