Friday, September 18, 2015

Software Clock

Compile the following code in the qb45 or freebasic compiler.  (c:\>fbc -lang qb clock.bas). Porting to C should be a piece of cake.

[code]
 '=====================================================================
' thetimeis
' author: computothought
'---------------------------------------------------------------------
' housekeeping
' arrays
dim blank$(7)
dim num$(10,10)
dim colon$(7)

' data
num$(0, 1) = "  ###  "
num$(0, 2) = " #   # "
num$(0, 3) = "# #   #"
num$(0, 4) = "#  #  #"
num$(0, 5) = "#   # #"
num$(0, 6) = " #   # "
num$(0, 7) = "  ###  "

num$(1, 1) = "   #   "
num$(1, 2) = "  ##   "
num$(1, 3) = " # #   "
num$(1, 4) = "   #   "
num$(1, 5) = "   #   "
num$(1, 6) = "   #   "
num$(1, 7) = " ##### "

num$(2, 1) = " ##### "
num$(2, 2) = "#     #"
num$(2, 3) = "      #"
num$(2, 4) = " ##### "
num$(2, 5) = "#      "
num$(2, 6) = "#      "
num$(2, 7) = "#######"

num$(3, 1) = " ##### "
num$(3, 2) = "#     #"
num$(3, 3) = "      #"
num$(3, 4) = " ##### "
num$(3, 5) = "      #"
num$(3, 6) = "#     #"
num$(3, 7) = " ##### "

num$(4, 1) = "#      "
num$(4, 2) = "#    # "
num$(4, 3) = "#    # "
num$(4, 4) = "#######"
num$(4, 5) = "     # "
num$(4, 6) = "     # "
num$(4, 7) = "     # "

num$(5, 1) = "#######"
num$(5, 2) = "#      "
num$(5, 3) = "#      "
num$(5, 4) = " ##### "
num$(5, 5) = "      #"
num$(5, 6) = "#     #"
num$(5, 7) = " ##### "

num$(6, 1) = " ##### "
num$(6, 2) = "#     #"
num$(6, 3) = "#      "
num$(6, 4) = "###### "
num$(6, 5) = "#     #"
num$(6, 6) = "#     #"
num$(6, 7) = " ##### "

num$(7, 1) = "#######"
num$(7, 2) = "#    # "
num$(7, 3) = "    #  "
num$(7, 4) = "   #   "
num$(7, 5) = "  #    "
num$(7, 6) = "  #    "
num$(7, 7) = "  #    "

num$(8, 1) = " ##### "
num$(8, 2) = "#     #"
num$(8, 3) = "#     #"
num$(8, 4) = " ##### "
num$(8, 5) = "#     #"
num$(8, 6) = "#     #"
num$(8, 7) = " ##### "

num$(9, 1) = " ##### "
num$(9, 2) = "#     #"
num$(9, 3) = "#     #"
num$(9, 4) = " ######"
num$(9, 5) = "      #"
num$(9, 6) = "#     #"
num$(9, 7) = " ##### "

blank$(1) = "       "
blank$(2) = "       "
blank$(3) = "       "
blank$(4) = "       "
blank$(5) = "       "
blank$(6) = "       "
blank$(7) = "       "

colon$(1) = "  # "
colon$(2) = " # #"
colon$(3) = "  # "
colon$(4) = "    "
colon$(5) = "  # "
colon$(6) = " # #"
colon$(7) = "  # "

'--------------------------------------------------------------------
'the logic
cls
locate 10,2: print"                                                                            #"
locate 11,2: print"  #####  #    #  ######     #####     #    #    #  ######    #     ####    # #"
locate 12,2: print"    #    #    #  #            #       #    ##  ##  #         #    #         #"
locate 13,2: print"    #    ######  #####        #       #    # ## #  #####     #     ####"
locate 14,2: print"    #    #    #  #            #       #    #    #  #         #         #    #"
locate 15,2: print"    #    #    #  #            #       #    #    #  #         #    #    #   # #"
locate 16,2: print"    #    #    #  ######       #       #    #    #  ######    #     ####     #"
locate 17,2: print ""

locate 20,20: print colon$(1);
locate 21,20: print colon$(2);
locate 22,20: print colon$(3);
locate 23,20: print colon$(4);
locate 24,20: print colon$(5);
locate 25,20: print colon$(6);
locate 26,20: print colon$(7);

locate 20,50: print colon$(1);
locate 21,50: print colon$(2);
locate 22,50: print colon$(3);
locate 23,50: print colon$(4);
locate 24,50: print colon$(5);
locate 25,50: print colon$(6);
locate 26,50: print colon$(7);


true% = -1
while true%

hrl$ = mid$(TIME$, 1,1): minl$ = MID$(TIME$, 4, 1): secl$ = mid$(TIME$, 7,1)
hrr$ = mid$(TIME$, 2,1): minr$ = MID$(TIME$, 5, 1): secr$ = mid$(TIME$, 8,1)

' hour left
    locate 20,1: print num$(val(hrl$), 1);
    locate 21,1: print num$(val(hrl$), 2);
    locate 22,1: print num$(val(hrl$), 3);
    locate 23,1: print num$(val(hrl$), 4);
    locate 24,1: print num$(val(hrl$), 5);
    locate 25,1: print num$(val(hrl$), 6);
    locate 26,1: print num$(val(hrl$), 7);

'hour right
    locate 20,10: print num$(val(hrr$), 1);
    locate 21,10: print num$(val(hrr$), 2);
    locate 22,10: print num$(val(hrr$), 3);
    locate 23,10: print num$(val(hrr$), 4);
    locate 24,10: print num$(val(hrr$), 5);
    locate 25,10: print num$(val(hrr$), 6);
    locate 26,10: print num$(val(hrr$), 7);

'minute left
    locate 20,30: print num$(val(minl$), 1);
    locate 21,30: print num$(val(minl$), 2);
    locate 22,30: print num$(val(minl$), 3);
    locate 23,30: print num$(val(minl$), 4);
    locate 24,30: print num$(val(minl$), 5);
    locate 25,30: print num$(val(minl$), 6);
    locate 26,30: print num$(val(minl$), 7);

'minute right
    locate 20,40: print num$(val(minr$), 1);
    locate 21,40: print num$(val(minr$), 2);
    locate 22,40: print num$(val(minr$), 3);
    locate 23,40: print num$(val(minr$), 4);
    locate 24,40: print num$(val(minr$), 5);
    locate 25,40: print num$(val(minr$), 6);
    locate 26,40: print num$(val(minr$), 7);

'second left
    locate 20,60: print num$(val(secl$), 1);
    locate 21,60: print num$(val(secl$), 2);
    locate 22,60: print num$(val(secl$), 3);
    locate 23,60: print num$(val(secl$), 4);
    locate 24,60: print num$(val(secl$), 5);
    locate 25,60: print num$(val(secl$), 6);
    locate 26,60: print num$(val(secl$), 7);

'Second right
    locate 20,70: print num$(val(secr$), 1);
    locate 21,70: print num$(val(secr$), 2);
    locate 22,70: print num$(val(secr$), 3);
    locate 23,70: print num$(val(secr$), 4);
    locate 24,70: print num$(val(secr$), 5);
    locate 25,70: print num$(val(secr$), 6);
    locate 26,70: print num$(val(secr$), 7);
wend
[/code]

No comments:

Post a Comment