/* Each LCD display is a 5x8 grid. Starting in the top-left and working across, each square has a number from 0 to 35 (later turned into a class "number0", "number1", etc). The numberGroup array holds which squares in the grid should be "active" in order to display the number. I worked this out by coloring a piece of paper. */ var numberGroup = {}; numberGroup[0] = [1,2,3,5,9,10,14,15,19,20,24,25,29,30,34,36,37,38]; numberGroup[1] = [2,6,7,12,17,22,27,32,36,37,38]; numberGroup[2] = [1,2,3,5,9,14,18,22,26,30,35,36,37,38,39]; numberGroup[3] = [1,2,3,5,9,14,17,18,24,29,30,34,36,37,38]; numberGroup[4] = [3,7,8,11,13,15,18,20,21,22,23,24,28,33,38]; numberGroup[5] = [0,1,2,3,4,5,10,15,16,17,18,24,29,30,34,36,37,38]; numberGroup[6] = [2,3,6,10,15,16,17,18,20,24,25,29,30,34,36,37,38]; numberGroup[7] = [0,1,2,3,4,9,13,18,22,27,31,36]; numberGroup[8] = [1,2,3,5,9,10,14,16,17,18,20,24,25,29,30,34,36,37,38]; numberGroup[9] = [1,2,3,5,9,10,14,15,19,21,22,23,24,29,33,36,37]; /* The buildBlock function is called when the six grids are being made. It loops through each individual pixel and determines which numbers in the display switch this pixel on. It then creates a string of classes for each pixel. For example, the classes string for the top-left (0) pixel are "number5 number7". */ function buildBlock(x) { var blockClass = ''; for (y = 0; y < 10; y++) { /* look to see which of the numberGroup arrays this pixel is located in. If found, add it to the class list (prefixing each number with "number") */ if (numberGroup[y].indexOf(x) > -1) { blockClass = blockClass + 'number' + y + ' '; } } //spit out the result return blockClass } /* displayNumber is called to switch the pixels around for each second. className: Which grid we're referring to (e.g. hourTen, hourUnit, minTen etc.) number: The number that grid needs to display */ function displayNumber(className, number) { var className = '.' + className; var number = '.number' + number; var selector = className + ' ' + number; //remove "active" class from all pixels $(className + ' .block-wrapper').removeClass("active"); //add "active" class to the pixels that will display the correct number. $(selector).addClass("active"); } /* timeFunc is the ticking clock. Every second it uses moment.js to get the current time, which is split up into each individual number. Each number is then sent to displayNumber() to activate the relevant pixels for the grid. */ function timeFunc() { setInterval(function() { var now = moment(); var hours = moment(now).format('HH').split(''); var minutes = moment(now).format('mm').split(''); var seconds = moment(now).format('ss').split(''); displayNumber('hourTen', hours[0]); displayNumber('hourUnit', hours[1]); displayNumber('minTen', minutes[0]); displayNumber('minUnit', minutes[1]); displayNumber('secTen', seconds[0]); displayNumber('secUnit', seconds[1]); }, 1000); } /* The start of everything. This function inserts the pixels into the grids, with classes that refer to the number that pixel helps to display (see: buildBlock()). Once built, it starts the clock with timeFunc(). */ $(document).ready(function () { for (i = 0; i < 40; i++) { var classBlock = buildBlock(i); $('.blockHolder').append('<div class="' + classBlock + 'block-wrapper"><div class="block-inner"><div class="block"></div><div class="block back"></div></div></div>'); } timeFunc(); });

!