Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="container"></div>
            
          
!

CSS

            
              #container {
  position:relative;
  width:983px;
  height:368px;
  margin:40px auto;
  border: 8px solid #000;
}

svg {
  position:absolute;
  width:40px;
  height:40px;
  fill: white;
  stroke: black;
  stroke-width: 1;
  transform: rotate(-90deg);
  
  circle {
    stroke:rgba(0,0,0,0.1);
  }
  
  .minute,
  .hour {
    stroke-width: 2;
    transform: translate(20px, 20px) rotate(0deg);
    -webkit-transition: transform 3.5s ease-in-out;
    transition: transform 3.5s ease-in-out;    
  }
  .minute {
    transform: translate(20px, 20px) rotate(-90deg);
  }
  .hour {
    transform: translate(20px, 20px) rotate(90deg);
  } 
}
            
          
!

JS

            
              var queue = []; // animation queue
var scenes = ["time", "random", "analog"]; // scene order
var cur_scene = -1;

// paint artwork
drawClocks(); 

// kickoff
setTimeout(function(){

  setInterval( handleQueue, 10 );
  setInterval( nextScene, 12000);
  nextScene();

}, 150);

/**
 * animate to a scene
 */
function nextScene() {
  cur_scene = cur_scene<scenes.length-1?cur_scene+1:0;
  console.log( scenes[cur_scene] );
  switch(scenes[cur_scene]) {
      
    case "time":
      for (var col=0; col<23; col++) {
        for (var row=0; row<8; row++) {
          setClock( col, row, [90, -90] );
        }
      }
      var t = new Date();
      var vals = [
        t.getHours()<10 ? 0 : String(t.getHours()).substring(0, 1),
        t.getHours()<10 ? t.getHours() : String(t.getHours()).substring(1, 2),
        t.getMinutes()<10 ? 0 : String(t.getMinutes()).substring(0, 1),
        t.getMinutes()<10 ? t.getMinutes() : String(t.getMinutes()).substring(1, 2)
      ];
      setDigit( 1, vals[0] );  
      setDigit( 6, vals[1] );  
      setClock( 11, 2, [0, 180] );
      setClock( 11, 5, [0, 180] );
      setDigit( 12, vals[2] );  
      setDigit( 17, vals[3] );  
      break;
      
    case 'random':
      for (var col=0; col<23; col++) {
        for (var row=0; row<8; row++) {
          setClock( col, row, [Math.random()*360, Math.random()*360] );
        }
      }
      break;
      
    case 'analog':
      var t = new Date();
      for (var col=22; col>=0; col--) {
        for (var row=0; row<8; row++) {
          setClock( col, row, [t.getHours()*(360/12), t.getMinutes()*6] );
        }
      }
      break;
  }
}

/**
 * queues a complete digit of 5 x 6 clocks, starting at position n
 */
function setDigit( d, n ) {
  var svg, hour, minute, char, rots;
  var chars = charDB[n];
  for (var c=0; c<5; c++) {
    for (var r=0; r<6; r++) {
      setClock( c+d, r+1, mapDB[chars[r][c]] );
    }
  }
}

/**
 * queues a clock to particular rotations
 */
function setClock( c, r, rots ) {
  addToQueue("c-"+String(c)+"-"+String(r), rots);
}

function addToQueue(id, rots) {
    queue.push({id:id, hour:rots[0], minute:rots[1]});
}

function handleQueue() {
  if (queue.length) {
    var item = queue.shift();
    var svg = document.getElementById(item.id);
    var hour = svg.getElementsByTagName('line')[0];
    hour.style.transform = "translate(20px, 20px) rotate("+item.hour+"deg)";
    var minute = svg.getElementsByTagName('line')[1];
    minute.style.transform = "translate(20px, 20px) rotate("+item.minute+"deg)";
  }  
}

/**
 * draws all clocks
 */
function drawClocks() {
  var container = document.getElementById('container');
  for (var col=0; col<23; col++) {
    for (var row=0; row<8; row++) {
      // base svg
      var svg = createElem( 'svg', {viewBox:'0 0 40 40'}, {left:20+col*41, top:20+row*41} );
      svg.id = "c-"+String(col)+"-"+String(row);
      container.appendChild(svg);

      // clock plate
      var c = createElem( 'circle', {cx:20, cy:20, r:19} );
      svg.appendChild(c);

      // hands
      svg.appendChild( createElem( 'line', {x1:0, x2:14, class:"hour" } ) );
      svg.appendChild( createElem( 'line', {x1:0, x2:17, class:"minute"} ) );
      
      // initial
      var hour = svg.getElementsByTagName('line')[0];
      hour.style.transform = "translate(20px, 20px) rotate("+Math.round(Math.random()*360)+"deg)";
      var minute = svg.getElementsByTagName('line')[1];
      minute.style.transform = "translate(20px, 20px) rotate("+Math.round(Math.random()*360)+"deg)";
    }
  }
}

/**
 * svg factory
 */
function createElem(type, attribs, pos) {
  var elem = document.createElementNS('http://www.w3.org/2000/svg', type);
  for(var key in attribs) {
    elem.setAttributeNS(null, key, attribs[key]);
  }
  if (pos) {
    elem.style.left = pos.left ? pos.left+"px" : 0;
    elem.style.top = pos.top ? pos.top+"px" : 0;
  }
  return elem;
}

/**
 * map ascii drawing characters to rotations
 */
var mapDB = {
	'┘': [   0, -90],
	'└': [   0,  90],
	'┐': [ -90, 180],
	'┌': [  90, 180],
	'|': [   0, 180],
	'-': [ -90,  90] 
};

/**
 * maps digits to ascii drawing characters
 */
var charDB = [
	[ 
		'┌---┐',
		'|┌-┐|',
		'||-||',
		'||-||',
		'|└-┘|',
		'└---┘'
	], [ 
		'--┌┐-',
		'--||-',
		'--||-',
		'--||-',
		'--||-',
		'--└┘-'
	], [ 
		'┌---┐',
		'└--┐|',
		'┌--┘|',
		'|┌--┘',
		'|└--┐',
		'└---┘'
	], [ 
		'┌---┐',
		'└--┐|',
		'┌--┘|',
		'└--┐|',
		'┌--┘|',
		'└---┘'
	], [ 
		'┌┐-┌┐',
		'||-||',
		'|└-┘|',
		'└--┐|',
		'---||',
		'---└┘'
	], [ 
		'┌---┐',
		'|┌--┘',
		'|└--┐',
		'└--┐|',
		'┌--┘|',
		'└---┘'
	], [ 
		'┌┐---',
		'||---',
		'|└--┐',
		'|┌-┐|',
		'|└-┘|',
		'└---┘'
	], [ 
		'┌--┐-',
		'└-┐|-',
		'--||-',
		'--||-',
		'--||-',
		'--└┘-'
	], [ 
		'┌---┐',
		'|┌-┐|',
		'|└-┘|',
		'|┌-┐|',
		'|└-┘|',
		'└---┘'
	], [ 
		'┌---┐',
		'|┌-┐|',
		'|└-┘|',
		'└--┐|',
		'---||',
		'---└┘'
	]
];
            
          
!
999px

Console