Guest User

Untitled

a guest
Jan 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <canvas id="myCanvas" width="1250" height="120"></canvas>
  2.  
  3. <script>
  4.  
  5. var canvas = $("#myCanvas")[0];
  6. var c = canvas.getContext("2d");
  7. var amount = 0;
  8. var startX = 164;
  9. var startY = 120;
  10. var endX = 1094;
  11. var endY = 120;
  12.  
  13. setTimeout(function() {
  14. var interval = setInterval(function() {
  15. amount += 0.005; // change to alter duration
  16. if (amount > 1) {
  17. amount = 1;
  18. clearInterval(interval);
  19. }
  20. c.clearRect(0, 0, canvas.width, canvas.height);
  21. c.strokeStyle = "black";
  22. c.lineWidth=1;
  23. c.strokeStyle="#707070";
  24. c.moveTo(startX, startY);
  25. // lerp : a + (b - a) * f
  26. c.lineTo(startX + (endX - startX) * amount, startY + (endY - startY) * amount);
  27. c.stroke();
  28. }, 0);
  29.  
  30. }, 3000);
  31.  
  32. </script>
  33.  
  34. this.canvas = canvas;
  35. this.context = this.canvas.getContext("2d");
  36. var _this = this;
  37. var setDim = function() {
  38. _this.w = _this.canvas.clientWidth;
  39. _this.h = _this.canvas.clientHeight;
  40. _this.canvas.width = _this.w;
  41. _this.canvas.height = _this.h;
  42. _this.dimChanged = true;
  43. _this.draw();
  44. };
  45. setDim();
  46. $(window).resize(setDim);
Add Comment
Please, Sign In to add comment