Another binary clock...

Recommended Posts

I think I had created one of these a long time ago.. but I made the code way too complicated. In this one, I took advantage of the fact that binary clocks are just based off of the base ten system of telling time. What I means is this: At any given time (e.g. 21:53:23) you can just take each number (2,1,5,2..), convert it to binary, and set it up in a column and you've got a binary clock. (e.g. 2 to 02, 1 to 1, 5 to 101....).

I was thinking of making a screensaver of this but it seemed like too much trouble.

Needs latest autoit (or a one of the older version's newer beta's for AdLibRegister/Unrigster)

```#noTrayIcon
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('GUIOnEventMode', 1)

Global Const \$WIDTH = @DesktopWidth, \$HEIGHT = @DesktopHeight + 30
Global Const \$X_CONST = \$WIDTH / 10, \$Y_CONST = \$HEIGHT / 6, \$SIZE = \$X_CONST * .85
;~ Global Const \$bkColor = 0x000000, \$active = 0x00FF00, \$inactive = 0x000F00
;~ Global Const \$bkColor = 0x000000, \$active = 0xFF0000, \$inactive = 0x0F0000
Global Const \$bkColor = 0x000000, \$active = 0x0000FF, \$inactive = 0x000000F
Global \$ctrls[4][6]

_CreateGUI()

_SetClock()

While 1
Sleep(200)
WEnd

Func _CreateGUI()
\$mainGUI = GUICreate('', \$WIDTH, \$HEIGHT, -1, -1, \$WS_POPUPWINDOW, BitOR(\$WS_EX_TOPMOST, \$WS_EX_TOOLWINDOW))
GUISetOnEvent(\$GUI_EVENT_CLOSE, '_Exit')
GUISetBkColor(\$bkColor)

Local \$colIndices[6] = [1, 2, 4, 5, 7, 8]
Local \$rowLimits[6] = [3, 1, 2, 1, 2, 1]

For \$i = 0 to 5
For \$j = \$rowLimits[\$i] to 4
\$ctrls[\$j - 1][\$i] = GUICtrlCreateLabel('', \$X_CONST * \$colIndices[\$i], \$Y_CONST * \$j, \$SIZE, \$SIZE)
Next
Next
GUISetState()
EndFunc

Func _SetClock()
\$time = StringSplit(@HOUR & @MIN & @SEC, '')
For \$i = 0 to 5
\$temp = _GetResult(Int(\$time[\$i + 1]))
For \$j = 0 to 3
If \$temp[\$j] = 1 then
GUICtrlSetBkColor(\$ctrls[\$j][\$i], \$active)
Else
GUICtrlSetBkColor(\$ctrls[\$j][\$i], \$inactive)
EndIf
Next
Next
EndFunc

Func _GetResult(\$n) ; n is between 0 and 9
Local \$ret[4] = [0, 0, 0, 0] ; 0 is 8, 1, 4..
If BitAND(\$n, 8) then \$ret[0] = 1
If BitAnd(\$n, 4) then \$ret[1] = 1
If BitAND(\$n, 2) then \$ret[2] = 1
If BitAND(\$n, 1) then \$ret[3] = 1
Return \$ret
EndFunc

Func _Exit()
Exit
EndFunc```

Edit: Let me know if you have any resolutions problems.. I think I wrote in a way that would work well on any monitor but I haven't checked at all.

Edited by Achilles

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share on other sites

But does it fade the buttons in and out?

That is a lot better than my version, the stringsplit is good.

Mat

Edit: Also note that this is the third attempt (that I know of)

Edited by Mat

Share on other sites

Hi!

but I made the code way too complicated.

Perhaps you will find my (old = 2008) code too much complicated?

```Dim \$bit[2]=["0","1"]
For \$x=1 To 60
sleep(990)
ToolTip(nbbin(@HOUR) & nbbin(@MIN) & nbbin(@SEC), 10, 10)
Next

Func nbbin(\$nb)
\$bits = " "
For \$j = 5 To 0 Step -1
\$bits &= \$bit[BitAND(Int(\$nb),2^\$j)/2^\$j]
Next
Return \$bits & @CRLF
EndFunc```
Edited by Michel Claveau

Share on other sites

But does it fade the buttons in and out?

That is a lot better than my version, the stringsplit is good.

Mat

Edit: Also note that this is the third attempt (that I know of)

I think there might be more older ones.. lol, no the buttons don't fade but I don't think it would be too hard to add that.

Hi!

Perhaps you will find my (old = 2008) code too much complicated?

```Dim \$bit[2]=["0","1"]
For \$x=1 To 60
sleep(990)
ToolTip(nbbin(@HOUR) & nbbin(@MIN) & nbbin(@SEC), 10, 10)
Next

Func nbbin(\$nb)
\$bits = " "
For \$j = 5 To 0 Step -1
\$bits &= \$bit[BitAND(Int(\$nb),2^\$j)/2^\$j]
Next
Return \$bits & @CRLF
EndFunc```

If I understand your code right it just shows the time in binary, which it does very efficiently. However, if my understanding of binary clocks is right, binary clocks don't show the time in binary. They show each number in binary, not the total. For example: the time is 12:34:56, a binary clock will show the binary representation of each number (1,2,3..) in a series of columns whereas your code shows the actual binary result of 12, 34, and 56.

Although, your nbbin function is shorter (not sure if more efficient) then what I'm using for converting a number to binary. But it basically uses the same principle..

Thanks to both for your input. Did the resolution work fine?

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Create an account

Register a new account