JavaScript implementation of a binary display of clock code

From , 3 Years ago, written in JavaScript, viewed 236 times.
URL https://pastebin.vip/view/f8417d04
  1. /*******************************************************************************
  2. * Snarkles.Net Useless Binary Time (SNUBT)
  3. *
  4. * ThinkGeek's Binary LED Clock... in JavaScript!
  5. * http://www.thinkgeek.com/cubegoodies/lights/59e0/
  6. *
  7. * Author: snarkles - http://snarkles.net/ - scripts [at] snarkles [dot] net
  8. * Date: 09-Mar-2004
  9. *
  10. * Feel free to use this on your site, but please leave these comments
  11. * in tact. Thanks. :)
  12. *******************************************************************************/
  13.  
  14.   // Convert current time to binary
  15.   function binaryize() {
  16.     resetPanel();
  17.     var time = getCurrentTime();
  18.     for (i = 1; i <= time.length; i++) {
  19.       num = time.charAt(i - 1);
  20.       for (j = 8; j >= 1; j = j / 2) {                 
  21.         if (num - j >= 0) {
  22.           eval("document.images.C" + i + j + ".src = 'on.gif'");
  23.           num = num - j;
  24.         }
  25.       }
  26.     }
  27.     updateClock();
  28.   }
  29.  
  30.   // Reset panel so all images are off
  31.   function resetPanel() {
  32.     for (i = 0; i < document.images.length; i++) {
  33.       document.images[i].src = "off.gif";
  34.     }
  35.   }
  36.        
  37.   // Get current time, return as 6-digit string: HHMMSS
  38.   function getCurrentTime() {
  39.     var now = new Date();
  40.     var hours = zeropad(now.getHours());
  41.     var minutes = zeropad(now.getMinutes());
  42.     var seconds = zeropad(now.getSeconds());
  43.     var time = hours + "" + minutes + "" + seconds;
  44.     return time;
  45.   }
  46.  
  47.   // Pad numbers < 10 with zeroes
  48.   function zeropad(num) {
  49.     if (num < 10) {
  50.       return "0" + num;
  51.     } else {
  52.       return num;
  53.     }
  54.   }
  55.  
  56.   // Update the clock every second
  57.   function updateClock() {
  58.     setTimeout("binaryize()", 1000);
  59.   }
  60. //javascript/1972

Reply to "JavaScript implementation of a binary display of clock code"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website