-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patharray.html
More file actions
48 lines (38 loc) · 843 Bytes
/
array.html
File metadata and controls
48 lines (38 loc) · 843 Bytes
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
<style>
canvas {
border: 1px solid #eee;
}
</style>
<script src="../build/build.js"></script>
<canvas width=1000 height=500></canvas>
<script>
var Tween = require('tween');
var raf = require('component-raf');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var h = 500;
function random(n, f) {
var arr = [];
while (n--) arr.push(Math.random() * f);
return arr;
}
var tween = Tween(random(1000, 50))
.ease('out-bounce')
.to(random(1000, 400))
.duration(800);
tween.update(function(a){
canvas.width = canvas.width;
ctx.fillStyle = '#0070ff';
for (var i = 0; i < a.length; i++) {
ctx.fillRect(i, h - a[i], 1, a[i]);
}
});
tween.on('end', function(){
animate = function(){};
});
function animate() {
raf(animate);
tween.update();
}
animate();
</script>