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

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="wrapper">
  <div class="content">
    <h1>Arclock</h1>
    <h2>Just An Arc Clock</h2>
  </div>
</div>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
            
          
!
            
              body {
      font-family: "Avenir", "Helvetica Neue", Helvetica, sans-serif;
      width: 100%;
      color: #000;
    }
    h1, h2 {
      text-transform: uppercase;
      text-align: center;
    }
    h1 {
      font-size: 48px;
      margin-top: 30px;
      margin-bottom: 0px;
    }
    h2 {
      font-size: 28px;
      color: #888;
    }

    /* SVG */
    svg.main {
      display: block;
      margin: 0 auto;
      margin-top: 30px;
    }
    .arc text {
      font: 10px sans-serif,
      text-anchor: middle;
    }
    .arc path {
      stroke: #fff;
    }
    .path-background {
      fill: #FCFBFD;
      stroke-width: 0px;
    }
    .path-foreground {
      fill: #011627;
    }
    .path-foreground-seconds {
      fill: #E71D36;
    }
    .label {
      font: 20px sans-serif;
      text-anchor: middle;
      fill: #011627;
    }
    .label-seconds {
      fill: #E71D36;
    }
            
          
!
            
              
    var width = 600;
    var height = 480;

    // Clock fields
    var fields = [
      { value: 60,
        size: 60,
        label: "s",
        update: function(date) { return date.getSeconds(); }
      },
      { value: 60,
        size: 60,
        label: "m:",
        update: function(date) { return date.getMinutes(); }
      },
      { value: 24,
        size: 24,
        label: "h:",
        update: function(date) { return date.getHours(); }
      }
    ];

    var arcMin = 75; // inner radius
    var arcWidth = 30; // width
    var arcPad = 1; // padding between arcs
    var cornerRadius = 14; // radius for rounded corner

    // Define arc for each field
    var arc = d3.svg.arc()
      .outerRadius(function(d, i) {
        return arcMin + ((i + 1) * arcWidth);
      })
      .innerRadius(function(d, i) {
        return arcMin + i * (arcWidth) + arcPad;
      })
      .startAngle(0)
      .endAngle(function(d, i) {
        return (d.value / d.size) * 2 * Math.PI;
      })
      .cornerRadius(function(d) {
        return cornerRadius;
      });

    var svg = d3.select(".wrapper")
      .append("svg")
      .attr("class", "main")
      .attr("width", width)
      .attr("height", height);

    var field = svg.selectAll(".field")
      .data(fields)
      .enter()
      .append("g")
      .attr("transform", function(d, i) {
        return "translate(" + width / 2 + "," + height / 2 + ")";
      })
      .attr("class", "field");

    field.append("path")
      .attr("class", "path path-background")
      .attr("d", arc);

    var path = field.append("path")
      .attr("class", function(d, i) {
        if (i === 0) {
          return "path path-foreground-seconds";
        }
        return "path path-foreground";
      });

    var label = field.append("text")
      .attr("class", function(d, i) {
        if (i === 0) {
          return "label label-seconds";
        }
        return "label";
      })
      .attr("dy", "0.35em")
      .attr("dx", function(d, i) {
        if (i === 0) {
          return "2.2em";
        }
        else if (i === 1) {
          return "0.2em";
        }
        else if (i === 2) {
          return "-2.2em";
        }
      });

    // Custom tween function draws intermediary steps of path
    function arcTween(d, i) {
      var interp = d3.interpolate({ value: d.previous }, d);
      return function(t) {
        var tmp = interp(t);
        return arc(interp(t), i);
      };
    }

    (function update() {
      var now = new Date();

      field.each(function(d) {
        d.previous = d.value;
        d.value = d.update(now);
      });

      path.transition()
        .ease("bounce")
        .duration(640)
        .attrTween("d", arcTween);

      label
        .text(function(d) {
          return d.value + d.label;
        });

      setTimeout(update, 1000 - (now % 1000));
    })();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console