Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div class="container">
  <svg width="250" height="250" viewbox="0 0 250 250">
    <path id="border" transform="translate(125, 125)"/>
  </svg>
  <span id="time" class="time">02:00</span></div>
</body>
</html>
 
    var intToTime = function(time) {
  var timeStr = time.toString();
  
  if (time < 10) {
    timeStr = '0' + timeStr;
  }
  
  return timeStr;
};
var polarToCartesian = function(centerX, centerY, radius, angleInDegrees) {
  var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;
  return {
    x: centerX + (radius * Math.cos(angleInRadians)),
    y: centerY + (radius * Math.sin(angleInRadians))
  };
};
var describeArc = function(x, y, radius, startAngle, endAngle){
    var start = polarToCartesian(x, y, radius, endAngle);
    var end = polarToCartesian(x, y, radius, startAngle);
    var arcSweep = endAngle - startAngle <= 180 ? "0" : "1";
    var d = [
        "M", start.x, start.y, 
        "A", radius, radius, 0, arcSweep, 0, end.x, end.y
    ].join(" ");
    return d;       
};
var border = document.getElementById("border");
var alpha  = 0;
var time   = document.getElementById("time");
var circleTime = 60000;
var oneTime = Math.floor(circleTime / 360);
var seconds = 0;
var minutes = 0;
border.setAttribute("class", describeArc(0, 0, 100, 0, 359.99999));
var start = new Date().getTime();
var round = Math.round;
  var lsec=0;
var animate = function() {
  var current = new Date().getTime();
  var diff    = current-start;
  if (diff >= 120000) {
    start = current;
    diff  = diff % 120000;
  }
  
  var alpha   = round((diff * 3)/1000);
  var seconds = round(diff/1000);
  seconds = seconds%60;
if(seconds === 59)
  {
    lsec = 1;
  }
  if(lsec === 1)
    {
      if(seconds === 0)
        {
          if(lsec === 1)
            {
              lsec =0;
              minutes++;
            }
        }
    }
  if(minutes < 2)
    {
  border.setAttribute("d", describeArc(0, 0, 100, alpha,360));
console.log(alpha);
 window.requestAnimationFrame(animate);      
    }
    time.innerHTML = intToTime(minutes) + ':' + intToTime(seconds);
};
animate();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Suresheepro
0viewers