<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |