Advertisement
Guest User

Untitled

a guest
Aug 8th, 2015
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title></title>
  6. </head>
  7. <body>
  8. <canvas id="canvasAnimation" width="600" height="600"></canvas>
  9. <style>
  10.     canvas {
  11.         border:1px solid black;
  12.     }
  13. </style>
  14.  
  15. <script>
  16.     var canvas = document.getElementById("canvasAnimation");
  17.     var ctx = canvas.getContext("2d");
  18.     var d = new Date();
  19.  
  20.     var timeUpdater = {
  21.         seconds: function () {
  22.             return (d.getSeconds() / 60) * (Math.PI * 2);
  23.         },
  24.         minutes: function () {
  25.             return (d.getMinutes() / 60) * (Math.PI * 2);
  26.         },
  27.         hours: function () {
  28.             return (d.getHours() / 24) * (Math.PI * 2);
  29.         }
  30.  
  31.     };
  32.     var secondsMask = {
  33.         color: "rgba(0, 0, 0, 1)",
  34.         x: canvas.width / 2,
  35.         y: canvas.height / 2,
  36.         radius: 300,
  37.         startAngle: 0,
  38.         endAngle: 2 * Math.PI,
  39.  
  40.         draw: function() {
  41.             ctx.beginPath();
  42.             ctx.fillStyle = this.color;
  43.             ctx.arc(this.x, this.y, this.radius, this.startAngle, this.endAngle);
  44.             ctx.fill();
  45.             ctx.closePath();
  46.         }
  47.     };
  48.  
  49.     var seconds = {
  50.         color: "rgba(100, 55, 0, 1)",
  51.         x: canvas.width / 2,
  52.         y: canvas.height / 2,
  53.         radius: 300,
  54.         startAngle: 0,
  55.         endAngle: timeUpdater.seconds(),
  56.  
  57.         draw: function() {
  58.             ctx.beginPath();
  59.             ctx.fillStyle = this.color;
  60.             ctx.arc(this.x, this.y, this.radius, this.startAngle, -this.endAngle, true);
  61.             ctx.lineTo(this.x, this.y);
  62.             ctx.fill();
  63.             ctx.closePath();
  64.         }
  65.     };
  66.  
  67.     var minutesMask = {
  68.         color: "rgba(0, 0, 0, 1)",
  69.         x: canvas.width / 2,
  70.         y: canvas.height / 2,
  71.         radius: 200,
  72.         startAngle: 0,
  73.         endAngle: 2 * Math.PI,
  74.  
  75.         draw: function() {
  76.             ctx.beginPath();
  77.             ctx.fillStyle = this.color;
  78.             ctx.arc(this.x, this.y, this.radius, this.startAngle, this.endAngle);
  79.             ctx.fill();
  80.             ctx.closePath();
  81.         }
  82.     };
  83.  
  84.     var minutes = {
  85.         color: "rgba(255, 0, 0, 1)",
  86.         x: canvas.width / 2,
  87.         y: canvas.height / 2,
  88.         radius: 200,
  89.         startAngle: 0,
  90.         endAngle: timeUpdater.minutes(),
  91.  
  92.         draw: function() {
  93.             ctx.beginPath();
  94.             ctx.fillStyle = this.color;
  95.             ctx.arc(this.x, this.y, this.radius, this.startAngle, -this.endAngle, true);
  96.             ctx.lineTo(this.x, this.y);
  97.             ctx.fill();
  98.             ctx.closePath();
  99.         }
  100.     };
  101.  
  102.     var hoursMask = {
  103.         color: "rgba(0, 0, 0, 1)",
  104.         x: canvas.width / 2,
  105.         y: canvas.height / 2,
  106.         radius: 100,
  107.         startAngle: 0,
  108.         endAngle: 2 * Math.PI,
  109.  
  110.         draw: function() {
  111.             ctx.beginPath();
  112.             ctx.fillStyle = this.color;
  113.             ctx.arc(this.x, this.y, this.radius, this.startAngle, this.endAngle);
  114.             ctx.fill();
  115.             ctx.closePath();
  116.         }
  117.     };
  118.  
  119.     var hours = {
  120.         color: "rgba(0, 0, 255, 1)",
  121.         x: canvas.width / 2,
  122.         y: canvas.height / 2,
  123.         radius: 100,
  124.         startAngle: 0,
  125.         endAngle: timeUpdater.hours(),
  126.  
  127.         draw: function() {
  128.             ctx.beginPath();
  129.             ctx.fillStyle = this.color;
  130.             ctx.arc(this.x, this.y, this.radius, this.startAngle, -this.endAngle, true);
  131.             ctx.lineTo(this.x, this.y);
  132.             ctx.fill();
  133.             ctx.closePath();
  134.         }
  135.     };
  136.  
  137.     var draw = function() {
  138.         secondsMask.draw();
  139.         seconds.draw();
  140.         minutesMask.draw();
  141.         minutes.draw();
  142.         hoursMask.draw();
  143.         hours.draw();
  144.     };
  145.  
  146.     setInterval(draw(), 500);
  147.  
  148. </script>
  149. </body>
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement