Skip to content

Instantly share code, notes, and snippets.

@aleksblago
Created March 26, 2016 12:34
Show Gist options
  • Save aleksblago/cb4655cc4e8d890db270 to your computer and use it in GitHub Desktop.
Save aleksblago/cb4655cc4e8d890db270 to your computer and use it in GitHub Desktop.
Hexadecimal Clock

Hexadecimal Clock

A simple clock written in JavaScript where the numerical value for the hours, minutes, and seconds represent the hexadecimal value of the background.

A Pen by Aleks Blagojevich on CodePen.

License.

<div class="clock"></div>
<div class="color"></div>
var clock = document.querySelector('.clock'),
color = document.querySelector('.color');
function getTime() {
var time = new Date(),
hours = ('0' + time.getHours()).slice(-2),
minutes = ('0' + time.getMinutes()).slice(-2),
seconds = ('0' + time.getSeconds()).slice(-2);
return {
time : hours + ' : ' + minutes + ' : ' + seconds,
color : '#' + hours + minutes + seconds
}
}
function outputTime() {
var now = getTime();
document.body.style.background = now.color;
clock.innerHTML = now.time;
color.innerHTML = now.color;
}
setInterval(outputTime, 250);
@import url(https://fonts.googleapis.com/css?family=Fira+Mono:400);
body {
background: #000;
color: #FFF;
font-family: 'Fira Mono', sans-serif;
font-size: 50px;
transition: background 1s;
height: 100%;
text-align: center;
}
.clock,
.color {
display: block;
position: absolute;
top: 50%;
width: 100%;
text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
transform: translateY(-50%);
}
.color {
font-size: 20px;
top: 80%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment