Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Cute Binary Clock Example

Keywords: 	 binary clock

Just for fun, here is a clock that displays the time in binary. Maximized, it makes an interesting "screen saver".

Have some fun,
Russell


;Binary clock
;by Russell
;

AddExtender("wilx34i.dll")

DKBLUE="0,0,128"
BLUE="0,0,255"
LTBLUE="128,180,255"
LTGRAY="192,192,192"
GRAY="150,150,150"
DKGRAY="64,64,64"
GREEN="0,255,0"
RED="255,0,0"
BLACK="0,0,0"
WHITE="255,255,255"
YELLOW="255,255,0" 

BoxesUp("0,0,100,125",@normal)  
BoxCaption(1,"Time")
BoxNew(2,"0,0,1000,1000",0)
BoxColor(2,BLACK,0)     
BoxDrawRect(2,"0,0,1000,1000",2)
BoxDataTag(2,"Time")

; Assign window positions for binary 1 or 0 for hour, minute, second
; Since we'll only see a max value of 59 (111011), we only need 6 positions.
sec6 = "800,750,900,900" ;Position of seconds 1
sec5 = "660,750,760,900" ;                    2
sec4 = "520,750,620,900" ;                    4
sec3 = "380,750,480,900" ;                    8
sec2 = "240,750,340,900" ;                   16
sec1 = "100,750,200,900" ;                   32
min6 = "800,500,900,650"
min5 = "660,500,760,650"
min4 = "520,500,620,650"
min3 = "380,500,480,650"
min2 = "240,500,340,650"
min1 = "100,500,200,650"
hour6 = "800,250,900,400"
hour5 = "660,250,760,400"
hour4 = "520,250,620,400"
hour3 = "380,250,480,400"
hour2 = "240,250,340,400"
hour1 = "100,250,200,400"

clock12 = 1 ;If you want a 12 hour clock (AM/PM), set this to 1. Otherwise, hours are 0 - 23

while 1
  BoxDataClear(2,"Time")
  TOD = TimeYmdHms()

  hours = itemextract(4,TOD,":") ;Get the hour from the time of day
  if clock12 == 1 then
    if hours > 12 then
      hours = hours - 12
      BoxCaption(1,"PM")
    else
      BoxCaption(1,"AM")
    endif
  endif
  binhour = xBaseConvert(hours, 10, 2) ;Convert to binary
  binhour = StrFixLeft(binhour,"0",6) ;Pad left so we always have 6 digits (1 = 000001)
  for i = 6 to 1 by -1 ;For each binary postion "on", turn on that position in the clock
    if StrSub(binhour,i,1) == "1" then
      BoxColor(2,RED,0) ;on
    else
      BoxColor(2,BLACK,0) ;off
    endif
    BoxDrawCircle(2,hour%i%,2) ;Coordinates from above
  next

  minute = itemextract(5,TOD,":")
  binmin = xBaseConvert(minute, 10, 2)
  binmin = StrFixLeft(binmin,"0",6)
  for i = 6 to 1 by -1
    if StrSub(binmin,i,1) == "1" then
      BoxColor(2,BLUE,0)
    else
      BoxColor(2,BLACK,0)
    endif
    BoxDrawCircle(2,min%i%,2)
  next

  second = itemextract(6,TOD,":")
  binsec = xBaseConvert(second, 10, 2)
  binsec = StrFixLeft(binsec,"0",6)
  for i = 6 to 1 by -1
    if StrSub(binsec,i,1) == "1" then
      BoxColor(2,GREEN,0)
    else
      BoxColor(2,BLACK,0)
    endif
    BoxDrawCircle(2,sec%i%,2)
  next

  timedelay(1); lest we hog the CPU
endwhile

;eof

Article ID:   W14953