You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
842 B

  1. <style>
  2. canvas {
  3. border: 1px solid #eee;
  4. }
  5. </style>
  6. <script src="../build/build.js"></script>
  7. <canvas width=1000 height=500></canvas>
  8. <script>
  9. var Tween = require('tween');
  10. var raf = require('component-raf');
  11. var canvas = document.querySelector('canvas');
  12. var ctx = canvas.getContext('2d');
  13. var h = 500;
  14. function random(n, f) {
  15. var arr = [];
  16. while (n--) arr.push(Math.random() * f);
  17. return arr;
  18. }
  19. var tween = Tween(random(1000, 50))
  20. .ease('out-bounce')
  21. .to(random(1000, 400))
  22. .duration(800);
  23. tween.update(function(a){
  24. canvas.width = canvas.width;
  25. ctx.fillStyle = '#0070ff';
  26. for (var i = 0; i < a.length; i++) {
  27. ctx.fillRect(i, h - a[i], 1, a[i]);
  28. }
  29. });
  30. tween.on('end', function(){
  31. animate = function(){};
  32. });
  33. function animate() {
  34. raf(animate);
  35. tween.update();
  36. }
  37. animate();
  38. </script>