Guest User

Untitled

a guest
Aug 13th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5.  
  6. #canvas {
  7. border-radius: 100%;
  8. }
  9.  
  10. </style>
  11. </head>
  12. <body>
  13.  
  14. <canvas id="canvas" height="500" width="500"></canvas>
  15.  
  16. <script>
  17. var canvas = document.getElementById('canvas');
  18. var ctx = canvas.getContext("2d");
  19. ctx.shadowBlur = "15"
  20. ctx.lineWidth = 20;
  21. ctx.font = "20px Arial bold";
  22.  
  23. function getDeg(time) {
  24. return Math.PI * 2 / 360 * time;
  25. }
  26. function updateCanvas() {
  27.  
  28. ctx.fillStyle = "black";
  29. ctx.fillRect(0,0,500,500);
  30.  
  31. var now = new Date();
  32. var milliseconds = now.getMilliseconds();
  33. var seconds = now.getSeconds();
  34. var minutes = now.getMinutes();
  35. var hours = now.getHours();
  36. var secAndMS = seconds + (milliseconds/1000);
  37. var minAndSec = minutes + (seconds/60);
  38. var hourAndMin = hours + (minutes/60);
  39.  
  40. ctx.shadowColor = "white";
  41. ctx.strokeStyle = "white";
  42. ctx.fillStyle = "white";
  43. ctx.beginPath();
  44. ctx.arc(250,250,100,getDeg(milliseconds * 0.36 -180),getDeg(milliseconds * 0.36 -90));
  45. ctx.stroke();
  46.  
  47. ctx.shadowColor = "#28d1fa";
  48. ctx.strokeStyle = "#28d1fa";
  49. ctx.fillStyle = "#28d1fa";
  50. ctx.fillText("Seconds: " + seconds, 195, 230);
  51. ctx.beginPath();
  52. ctx.arc(250,250,140,getDeg(270),getDeg(secAndMS * 6 -90));
  53. ctx.stroke();
  54.  
  55. ctx.shadowColor = "#FF33CC";
  56. ctx.strokeStyle = "#FF33CC";
  57. ctx.fillStyle = "#FF33CC";
  58. ctx.fillText("Minutes: " + minutes, 195, 260);
  59. ctx.beginPath();
  60. ctx.arc(250,250,180,getDeg(270),getDeg(minAndSec * 6 - 90));
  61. ctx.stroke();
  62.  
  63. ctx.shadowColor = "#33FF33";
  64. ctx.strokeStyle = "#33FF33";
  65. ctx.fillStyle = "#33FF33";
  66. ctx.fillText("Hours: " + hours, 195, 290);
  67. ctx.beginPath();
  68. ctx.arc(250,250,220,getDeg(270),getDeg(hourAndMin * 15 - 90));
  69. ctx.stroke();
  70.  
  71. }
  72.  
  73. setInterval(updateCanvas, 20);
  74. </script>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment