beannshie

Clock

Aug 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <html>
  2.  
  3. <canvas id="gameCanvas" width="1350" height="640"></canvas>
  4.  
  5. <script>
  6.  
  7. var second = 0
  8. var minute = 0
  9. var hour = 0
  10.  
  11. var paused = false
  12.  
  13. function countSec() {
  14. second ++
  15. }
  16.  
  17. function countMin() {
  18. if(second == 60) {
  19. second = 0;
  20. minute ++
  21. }
  22. }
  23.  
  24. function countHour() {
  25. if(minute == 60) {
  26. minute = 0;
  27. hour ++
  28. }
  29. }
  30.  
  31. window.onload = function() {
  32. canvas = document.getElementById('gameCanvas');
  33. canvasContext = canvas.getContext('2d');
  34.  
  35. var framesPerSecond = 1
  36. setInterval(function() {
  37. drawCounter();
  38. if(paused == false) {
  39. countSec();
  40. countMin();
  41. countHour();
  42. }
  43. }, 1000/framesPerSecond);
  44.  
  45. canvas.addEventListener('mousedown',handleMouseClick);
  46. }
  47.  
  48. function drawCounter() {
  49. drawRect(0,0, 750,750, 'white');
  50. canvasContext.font="40px Arial";
  51. canvasContext.fillStyle = 'blue';
  52.  
  53. canvasContext.fillText("Seconds", 50,50);
  54. canvasContext.fillText(second, 230,50);
  55.  
  56. canvasContext.fillText("Minutes", 50,100);
  57. canvasContext.fillText(minute, 230,100);
  58.  
  59. canvasContext.fillText("Hours", 50,150);
  60. canvasContext.fillText(hour, 230,150);
  61.  
  62. canvasContext.fillText(":", 215,50);
  63. canvasContext.fillText(":", 215,100);
  64. canvasContext.fillText(":", 215,150);
  65. }
  66.  
  67. function drawRect(leftX, topY, width, height, drawColor) {
  68. canvasContext.fillStyle = drawColor;
  69. canvasContext.fillRect(leftX, topY, width, height);
  70. }
  71.  
  72. function handleMouseClick(evt) {
  73. if(paused == false) {
  74. paused = true
  75. } else if(paused) {
  76. paused = false
  77. }
  78. }
  79.  
  80. </script>
  81.  
  82. <html>
Add Comment
Please, Sign In to add comment