Binaryish Clock
'Public Domain
Option Explicit
Type gl32type
pixel As Integer
clr As Integer
End Type
Sub PrintGlyph(obj() As gl32type, grow As Integer, gcol As Integer)
Dim As Integer i, j, row, col, scrw
Dim framebuffer As Integer Ptr
row = (grow - 1) * (Ubound(obj, 1) + 1)
col = (gcol - 1) * (Ubound(obj, 2) + 1)
framebuffer = Screenptr
If framebuffer Then
Screeninfo scrw
Screenlock
For i = Lbound(obj, 1) To Ubound(obj, 1)
For j = Lbound(obj, 2) To Ubound(obj, 2)
If obj(i, j).pixel = 1 Then
Poke Integer, framebuffer + ((row + i) * scrw) + (col + j), obj(i, j).clr
End If
Next
Next
Screenunlock
End If
End Sub
Dim As gl32type ledred(15, 15) => { _
{(0,0),(0,0),(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,12632256),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,12632256),(1,12632256),(1,12632256),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,12632256),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,16711680),(1,16711680),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0),(0,0)}, _
{(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)} _
}
Dim As gl32type ledblack(15, 15) => { _
{(0,0),(0,0),(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,12632256),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,12632256),(1,12632256),(1,12632256),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,12632256),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0)}, _
{(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0),(0,0)}, _
{(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,6579300),(1,8421481),(1,8421481),(1,6579300),(1,6579300),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(0,0),(0,0),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(1,8421481),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)}, _
{(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)} _
}
Dim As Double ctime
Dim As String bhour, bmin, bsec, ttime
Dim As Integer i, row, col
Screen 14, 32
Windowtitle "Tick Tock, Binary Clock"
Do
ctime = Now
'Get the binary time values
bhour = Bin(Hour(ctime))
If Len(bhour) < 6 Then
bhour = String(6 - Len(bhour), "0") & bhour
End If
bmin = Bin(Minute(ctime))
If Len(bmin) < 6 Then
bmin = String(6 - Len(bmin), "0") & bmin
End If
bsec = Bin(Second(ctime))
If Len(bsec) < 6 Then
bsec = String(6 - Len(bsec), "0") & bsec
End If
'Get the formatted time
ttime = Format(ctime, "hh:mm:ss AM/PM") & " (" & Format(ctime, "hh:mm:ss") & ")"
Locate 2, 20 - Len(ttime) / 2
Print ttime
'Print the binary digits
row = 5
col = 8
For i = 1 To Len(bhour)
If Mid(bhour, i, 1) = "1" Then
PrintGlyph ledred(), row, col
Else
PrintGlyph ledblack(), row, col
End If
col += 1
Next
row += 1
col = 8
For i = 1 To Len(bmin)
If Mid(bmin, i, 1) = "1" Then
PrintGlyph ledred(), row, col
Else
PrintGlyph ledblack(), row, col
End If
col += 1
Next
row += 1
col = 8
For i = 1 To Len(bsec)
If Mid(bsec, i, 1) = "1" Then
PrintGlyph ledred(), row, col
Else
PrintGlyph ledblack(), row, col
End If
col += 1
Next
Sleep 1
Loop Until Inkey ""