beannshie

Counter

Aug 22nd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <html>
  2.  
  3. <canvas id="gameCanvas" width="1350" height="640"></canvas>
  4.  
  5. <script>
  6.  
  7. var counter = 0
  8.  
  9. function count() {
  10. console.log(counter);
  11. counter ++
  12. }
  13.  
  14. window.onload = function() {
  15. canvas = document.getElementById('gameCanvas');
  16. canvasContext = canvas.getContext('2d');
  17.  
  18. var framesPerSecond = 30 //how many numbers are added per second
  19. setInterval(function() {
  20. drawCounter();
  21. count();
  22. }, 1000/framesPerSecond);
  23. }
  24.  
  25. function drawCounter() {
  26. drawRect(0,0, 750,750, 'white');
  27. canvasContext.font="40px Arial";
  28. canvasContext.fillStyle = 'blue';
  29. canvasContext.fillText("Counter :", 50,50);
  30. canvasContext.fillText(counter, 230,50);
  31. }
  32.  
  33. function drawRect(leftX, topY, width, height, drawColor) {
  34. canvasContext.fillStyle = drawColor;
  35. canvasContext.fillRect(leftX, topY, width, height);
  36. }
  37.  
  38. </script>
  39.  
  40. <html>
Advertisement
Add Comment
Please, Sign In to add comment