cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <canvas></canvas>
<div>
  Polar<br>
  <b>Clock</b><br>
</div>
  <span>// <a href="http://blog.pixelbreaker.com/polarclock"> Flash Polar Clock</a> by pixelbreaker</span>
            
          
!
            
              body{
  margin: 0;
  padding: 0;
  background: rgba(0, 0, 48, 1);
}

canvas{
  position: absolute;
  top: -webkit-calc(50% - 250px);
  top: calc(50% - 250px);
  left: -webkit-calc(50% - 300px);
  left: calc(50% - 300px);
  width: 600px;
  height: 600px;
}

div{
  position: absolute;
  top: 5px;
  left: 5px;
  color: #fff;
  font-size: 40px;
  font-family: Arial;
}

span{
  position: absolute;
  bottom: 5px;
  left: 5px;
  color: #666;
  font-size: 13px;
  font-family: Arial;
}

span a{
  text-decoration: none;
  color: #0579f5;
}
            
          
!
            
              var usr_color = 160; //Change value to change color scheme

window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame || 
    window.webkitRequestAnimationFrame || 
    window.mozRequestAnimationFrame    || 
    window.oRequestAnimationFrame      || 
    window.msRequestAnimationFrame     ||  
    function( callback ){
    window.setTimeout(callback, 1000 / 60);
  };
})();

var canvas = document.getElementsByTagName("canvas")[0];
var dpr = window.devicePixelRatio || 1;
var rect = canvas.getBoundingClientRect();
var w = rect.width * dpr;
var h = rect.height * dpr;
canvas.width = w;
canvas.height = h;
var ctx = canvas.getContext('2d');
ctx.scale(dpr, dpr);

var arcs = [];

function init(){
  console.log("init called");
  reset();
  arcs = [];
  var m = new arc();
  m.class = "month";
  arcs.push(m);
  
  var d = new arc();
  d.class = "date";
  d.r = 135;
  arcs.push(d);
  
  var d = new arc();
  d.class = "day";
  d.r = 170;
  arcs.push(d);
  
  var h = new arc();
  h.class = "hours";
  h.r = 205;
  arcs.push(h);
  
  var m = new arc();
  m.class = "mins";
  m.r = 240;
  arcs.push(m);
  
  var s = new arc();
  s.class = "secs";
  s.r = 275;
  arcs.push(s);
}

function arc(){
  this.class = "month";
  this.r = 100;
  this.rot = 1;
  
  this.draw = function(){
    ctx.beginPath();
    ctx.arc(300,300,this.r,(Math.PI/(2/3)),this.rot,false);
    ctx.lineWidth = 30;
    ctx.strokeStyle = "hsla("+(this.rot*(180/Math.PI)+usr_color)+",60%,50%,1)";
    ctx.stroke();
    
    ctx.save();
    ctx.fillStyle = "rgba(0, 0, 48, 1)";
    ctx.translate(300, 300);
    ctx.rotate(this.rot);
    ctx.font="bold 14px Arial";
    if(this.class == "secs"){
      var d = new Date();
      ctx.fillText(d.getSeconds(), 267, -5);
    }
    else if(this.class == "mins"){
      var d = new Date();
      ctx.fillText(d.getMinutes(), 232, -5);
    }
    else if(this.class == "hours"){
      var d = new Date();
      ctx.fillText(d.getHours(), 197, -5);
    }
    else if(this.class == "day"){
      var d = new Date();
      var day = d.getDay();
      if(day == 1){
        var day = "Mon"
      }
      else if(day == 2){
        var day = "Tue"
      }
      else if(day == 3){
        var day = "Wed"
      }
      else if(day == 4){
        var day = "Thu"
      }
      else if(day == 5){
        var day = "Fri"
      }
      else if(day == 6){
        var day = "Sat"
      }
      else if(day == 7){
        var day = "Sun"
      }
      ctx.fillText(day, 158, -5);
    }
    else if(this.class == "date"){
      var d = new Date();
      ctx.fillText(d.getDate(), 127, -5);
    }
    else if(this.class == "month"){
      var d = new Date();
      ctx.fillText(d.getMonth()+1, 93, -5);
    }
    ctx.restore();
  }
}

function reset(){
  ctx.fillStyle = "rgba(0, 0, 48, 1)";
  ctx.fillRect(0,0,w,h);
}

function draw(){
  reset();
  ctx.fillStyle = "rgba(255,255,255,0.8)";
  ctx.font = "12px Arial"
  ctx.fillText("seconds", 250, 27);
  ctx.fillText("minutes", 252, 63);
  ctx.fillText("hours", 264, 98);
  ctx.fillText("day", 274, 134);
  ctx.fillText("date", 270, 168);
  ctx.fillText("month", 260, 203);
  
  for(var i=0;i<arcs.length;i++){
    var a = arcs[i];
    var d = new Date();
    if(a.class == "month"){
      var n = d.getMonth()+1;
      a.rot = (n/12)*(Math.PI*2) - (Math.PI/2);
    }
    else if(a.class == "date"){
      var n = d.getDate();
      a.rot = (n/31)*(Math.PI*2) - (Math.PI/2);
    }
    else if(a.class == "day"){
      var n = d.getDay();
      a.rot = (n/7)*(Math.PI*2) - (Math.PI/2);
    }
    else if(a.class == "hours"){
      var n = d.getHours();
      var m = d.getMinutes();
      a.rot = ((n/12)*(Math.PI*2) - (Math.PI/2)) + ((m/3600)*(Math.PI*2));
    }
    else if(a.class == "mins"){
      var n = d.getMinutes();
      var s = d.getSeconds();
      a.rot = ((n/60)*(Math.PI*2) - (Math.PI/2)) + ((s/3600)*(Math.PI*2));
    }
    else if(a.class == "secs"){
      var n = d.getSeconds();
      var m = d.getMilliseconds();
      a.rot = ((n/60)*(Math.PI*2) - (Math.PI/2)) + ((m/60000)*(Math.PI*2));
    }
    a.draw();
  }
}

function animloop() {
  draw();
  requestAnimFrame(animloop); 
}

init();
animloop();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console