color watch

HTML

<div><strong><em></em><span></span></strong></div>

CSS

@import url(http://fonts.googleapis.com/css?family=Lato:900);
html,
body {
  height: 100%;
  font-family: 'Lato', sans-serif;
}

body {
  position: relative;
  height: 100%;
  /*-webkit-transition: background-color 150ms;
    -moz-transition: background-color 150ms;
    -ms-transition: background-color 150ms;
    -o-transition: background-color 150ms;
    transition: background-color 150ms;*/
}

div {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: inset 0 0 10000px rgba(0, 0, 0, .2);
}

div:after {
  position: absolute;
  content: "";
  top: 5px;
  right: 5px;
  bottom: 5px;
  left: 5px;
  border: 1px solid rgba(255, 255, 255, .4);
}

strong {
  position: absolute;
  text-align: center;
  width: 100%;
  height: 150px;
  left: 50%;
  top: 50%;
  margin: -75px 0 0 -50%;
  color: rgba(255, 255, 255, .5);
  font-size: 100px;
  font-weight: 900;
  text-shadow: 0 0 1000px rgba(0, 0, 0, .3), 0 2px 0 rgba(0, 0, 0, .1);
}

em {
  border-bottom: 1px solid rgba(255, 255, 255, .3);
}

span {
  width: 430px;
  position: relative;
  margin: 16px auto 0;
  display: block;
  font-size: 15px;
  text-align: right;
}

JavaScript

var timeToColor, ruleOfThree, zeroPad, interval, $body = $('body'),
  $clock, isRunning, start, $color;

$clock = $("strong em").eq(0);
$color = $("strong span").eq(0);

isRunning = true;

zeroPad = function(num, places) {
  var zero = places - num.toString().length + 1;
  return Array(+(zero > 0 && zero)).join("0") + num;
};

ruleOfThree = function(val, maxVal, relVal) {
  return ((maxVal || 100) * val) / relVal;
};

timeToColor = function(time) {
  var h, m, s;

  h = time.getHours();
  m = time.getMinutes();
  s = time.getSeconds();

  return Math.floor(ruleOfThree(s, 360, 60)) + "," + ruleOfThree(h, 100, 23).toFixed(2) + "%," + ruleOfThree(m, 100, 60).toFixed(2) + "%";
};

start = function() {
  interval = setInterval(function() {
    var color, time = new Date();
    color = timeToColor(time);
    $body.css("background-color", "hsl(" + color + ")");
    $clock.text(zeroPad(time.getHours(), 2) + "°" + zeroPad(time.getMinutes(), 2) + "°" + zeroPad(time.getSeconds(), 2));
    $color.text("HSL ( " + color + " )");
  }, 1000);
};

start();

$body.on("click", function() {
  if (isRunning) {
    clearInterval(interval);
    isRunning = false;
  } else {
    start();
    isRunning = true;
  }
});