Jump to content

Binary Clock


Mat
 Share

Recommended Posts

Based on this clock here:

http://www.thinkgeek.com/homeoffice/lights/59e0/

I liked the idea, so decided i'd make one! Its very simple, but its quite fun watching the binary ticking...

Global $sCode

Opt("GUIOnEventMode", 1)

GUICreate("Binary Clock", 140, 94, -1, -1, 0x00080000 + 0x00C00000)
GUISetOnEvent(-3, "_Exit")
GUISetBkColor(0)

Global $ahItems[7][5]

$ahItems[0][1] = GUICtrlCreateCheckbox("", 2, 50, 17, 17)
$ahItems[0][0] = GUICtrlCreateCheckbox("", 2, 74, 17, 17)

$ahItems[1][3] = GUICtrlCreateCheckbox("", 26, 2, 17, 17)
$ahItems[1][2] = GUICtrlCreateCheckbox("", 26, 26, 17, 17)
$ahItems[1][1] = GUICtrlCreateCheckbox("", 26, 50, 17, 17)
$ahItems[1][0] = GUICtrlCreateCheckbox("", 26, 74, 17, 17)

$ahItems[2][2] = GUICtrlCreateCheckbox("", 50, 26, 17, 17)
$ahItems[2][1] = GUICtrlCreateCheckbox("", 50, 50, 17, 17)
$ahItems[2][0] = GUICtrlCreateCheckbox("", 50, 74, 17, 17)

$ahItems[3][3] = GUICtrlCreateCheckbox("", 74, 2, 17, 17)
$ahItems[3][2] = GUICtrlCreateCheckbox("", 74, 26, 17, 17)
$ahItems[3][1] = GUICtrlCreateCheckbox("", 74, 50, 17, 17)
$ahItems[3][0] = GUICtrlCreateCheckbox("", 74, 74, 17, 17)

$ahItems[4][2] = GUICtrlCreateCheckbox("", 98, 26, 17, 17)
$ahItems[4][1] = GUICtrlCreateCheckbox("", 98, 50, 17, 17)
$ahItems[4][0] = GUICtrlCreateCheckbox("", 98, 74, 17, 17)

$ahItems[5][3] = GUICtrlCreateCheckbox("", 122, 2, 17, 17)
$ahItems[5][2] = GUICtrlCreateCheckbox("", 122, 26, 17, 17)
$ahItems[5][1] = GUICtrlCreateCheckbox("", 122, 50, 17, 17)
$ahItems[5][0] = GUICtrlCreateCheckbox("", 122, 74, 17, 17)

GUISetState()

While 1
    BOX_Update()
    Sleep(500)
WEnd

Func BOX_Update()
    $sCode = ""
    Local $aTime[3] = [@HOUR, @MIN, @SEC], $t, $n, $i
    For $t = 0 To 2
        If StringLen($aTime[$t]) = 2 Then
            $n = StringLeft($aTime[$t], 1)
            For $i = 0 To 2
                If BitAND($n, 2 ^ $i) Then ContinueLoop 1 + 0 * BOX_Add($t * 2, $i, 1)
                BOX_Add($t * 2, $i, 0)
            Next
            $aTime[$t] -= $n * 10
        EndIf
        For $i = 0 To 3
            If BitAND($aTime[$t], 2 ^ $i) Then ContinueLoop 1 + 0 * BOX_Add($t * 2 + 1, $i, 1)
            BOX_Add($t * 2 + 1, $i, 0)
        Next
    Next
    BOX_RunCode()
EndFunc   ;==>BOX_Update

Func BOX_Add($i, $x, $iTicked)
    $sCode &= @CRLF & $i & "," & $x & "," & $iTicked
EndFunc   ;==>BOX_Add

Func BOX_SetState($i, $x, $iTicked)
    $iTicked = (($iTicked - 1) * - 3) + 1
    If Not BitAND(GUICtrlGetState($ahItems[$i][$x]), $iTicked) Then GUICtrlSetState($ahItems[$i][$x], $iTicked)
EndFunc   ;==>BOX_SetState

Func BOX_RunCode()
    Local $aData = StringSplit($sCode, @CRLF, 1)
    For $i = 1 To $aData[0]
        $aParams = StringSplit($aData[$i], ",")
        $aParams[0] = "CallArgArray"
        Call("BOX_SetState", $aParams)
    Next
EndFunc   ;==>BOX_RunCode

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Mat

Edited by Mat
Link to comment
Share on other sites

Link to comment
Share on other sites

Scary.... Same title and everything. But I think my function for setting the time is slightly cleaner. ;)

Mat

Edit: That progress bar clock looks pretty good too.

Good fun education. is it possible to setup for a Vista or Windows 7 gadget? Just a thought.

thanks

Dr SherlockAlways a way

Link to comment
Share on other sites

Works good... Not very pretty but I'm sure you knew that when you made it; but still a few graphics would go a long way in making this thing looking nice. Plus, using checkboxes means that the user can check them which is kind of ghetto even though they are automatically unchecked every time you update the clock. The code is clean and easy to understand.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

I was thinking about graphics but no matter what I did I was disappointed. Simple circles etc should be no problem, and there are several ways I know of to do that. I would want a sort of fade in fade out thing, but my current script changes each state one by one, so that would need changing.

The other thing I am doing is trying to work on is an "all in one" clock. We certainly have enough clocks to do it, but its the whole framework i'm struggling with. My idea was to have a plugin structure where all the different clocks are stored as scripts, which are run by the mother program. I thought I could use _WinApi_SetParent to embed the new windo in the old one, but that didn't seem to work.

All that and i've got a new computer, and without thinking, deleted my snippets folder, which had a lot of very useful stuff in it. So don't expect anything for a while. But feel free to do it yourself.

Mat

Updated code. Cut the size by about 50%, and also made it so that all the changes are added to "$sCode", which is then implemented from a single function. This way it will be fairly simple to implement a fade in effect.

@nugame,

The implementation of a gadget is nothing more than an HTML page that is a maximum of 130 pixels wide. Though this isn’t readily evident, the main HTML file (the one referenced in the XML definition file) is actually loaded into an Internet Explorer® 7 window. There is, of course, no chrome surrounding this window and its location is controlled by Sidebar, but everything inside is basically a Web application. You have access to the DOM and most of the APIs as you would with a standard Web page. This means you can use AJAX techniques, create dynamic HTML elements, trap events, and so on

So there is no way directly with autoit, but it would not be hard for be me to do something.

Edited by Mat
Link to comment
Share on other sites

New code, now fades in and out (well... it looks like it does!)

Global Const $COLOR_Bk = 0x000000
Global Const $COLOR_On = 0xFFFFFF
Global Const $COLOR_Off = $COLOR_Bk


Global $COLOR_On_R = BitAND ($COLOR_On, 0xFF0000)
Global $COLOR_On_G = BitAND ($COLOR_On, 0xFF00)
Global $COLOR_On_B = BitAND ($COLOR_On, 0xFF)

Global $COLOR_Off_R = BitAND ($COLOR_Off, 0xFF0000)
Global $COLOR_Off_G = BitAND ($COLOR_Off, 0xFF00)
Global $COLOR_Off_B = BitAND ($COLOR_Off, 0xFF)

Global $COLOR_Step_R = ($COLOR_On_R - $COLOR_Off_R) / 51
Global $COLOR_Step_G = ($COLOR_On_G - $COLOR_Off_G) / 51
Global $COLOR_Step_B = ($COLOR_On_B - $COLOR_Off_B) / 51

Global $sCode

Opt("GUIOnEventMode", 1)

GUICreate("Binary Clock", 140, 94, -1, -1, 0x00080000 + 0x00C00000)
GUISetOnEvent(-3, "_Exit")
GUISetBkColor($COLOR_Bk)
GUICtrlSetDefBkColor ($COLOR_On)

Global $ahItems[7][5]

$ahItems[0][1] = GUICtrlCreateLabel("", 2, 50, 17, 17)
$ahItems[0][0] = GUICtrlCreateLabel("", 2, 74, 17, 17)

$ahItems[1][3] = GUICtrlCreateLabel("", 26, 2, 17, 17)
$ahItems[1][2] = GUICtrlCreateLabel("", 26, 26, 17, 17)
$ahItems[1][1] = GUICtrlCreateLabel("", 26, 50, 17, 17)
$ahItems[1][0] = GUICtrlCreateLabel("", 26, 74, 17, 17)

$ahItems[2][2] = GUICtrlCreateLabel("", 50, 26, 17, 17)
$ahItems[2][1] = GUICtrlCreateLabel("", 50, 50, 17, 17)
$ahItems[2][0] = GUICtrlCreateLabel("", 50, 74, 17, 17)

$ahItems[3][3] = GUICtrlCreateLabel("", 74, 2, 17, 17)
$ahItems[3][2] = GUICtrlCreateLabel("", 74, 26, 17, 17)
$ahItems[3][1] = GUICtrlCreateLabel("", 74, 50, 17, 17)
$ahItems[3][0] = GUICtrlCreateLabel("", 74, 74, 17, 17)

$ahItems[4][2] = GUICtrlCreateLabel("", 98, 26, 17, 17)
$ahItems[4][1] = GUICtrlCreateLabel("", 98, 50, 17, 17)
$ahItems[4][0] = GUICtrlCreateLabel("", 98, 74, 17, 17)

$ahItems[5][3] = GUICtrlCreateLabel("", 122, 2, 17, 17)
$ahItems[5][2] = GUICtrlCreateLabel("", 122, 26, 17, 17)
$ahItems[5][1] = GUICtrlCreateLabel("", 122, 50, 17, 17)
$ahItems[5][0] = GUICtrlCreateLabel("", 122, 74, 17, 17)

GUISetState()

While 1
    BOX_Update()
    Sleep(500)
WEnd

Func BOX_Update()
    $sCode = ""
    Local $aTime[3] = [@HOUR, @MIN, @SEC], $t, $n, $i
    For $t = 0 To 2
        If StringLen($aTime[$t]) = 2 Then
            $n = StringLeft($aTime[$t], 1)
            For $i = 0 To 2
                If BitAND($n, 2 ^ $i) Then ContinueLoop 1 + 0 * BOX_Add($t * 2, $i, 1)
                BOX_Add($t * 2, $i, 0)
            Next
            $aTime[$t] -= $n * 10
        EndIf
        For $i = 0 To 3
            If BitAND($aTime[$t], 2 ^ $i) Then ContinueLoop 1 + 0 * BOX_Add($t * 2 + 1, $i, 1)
            BOX_Add($t * 2 + 1, $i, 0)
        Next
    Next
    BOX_RunCode()
EndFunc   ;==>BOX_Update

Func BOX_Add($i, $x, $iTicked)
    $iTicked = (($iTicked - 1) * -16) + 16
    If Not BitAND(GUICtrlGetState($ahItems[$i][$x]), $iTicked) Then $sCode &= @CRLF & $i & "," & $x & "," & $iTicked
EndFunc   ;==>BOX_Add

Func BOX_SetState($i, $x, $iTicked)
    GUICtrlSetState($ahItems[$i][$x], $iTicked)
EndFunc   ;==>BOX_SetState

Func BOX_RunCode()
    Local $aData = StringSplit($sCode, @CRLF, 1)
    For $i = 1 To 51
        $nColor_In = BitOR ($COLOR_Off_R + ($COLOR_Step_R * $i), $COLOR_Off_G + ($COLOR_Step_G * $i), $COLOR_Off_B + ($COLOR_Step_B * $i))
        $nColor_Out = BitOR ($COLOR_On_R - ($COLOR_Step_R * $i), $COLOR_On_G - ($COLOR_Step_G * $i), $COLOR_On_B - ($COLOR_Step_B * $i))
        For $x = 1 To $aData[0]
            If $aData[$x] = "" Then ContinueLoop
            $aParams = StringSplit($aData[$x], ",")
            If $aParams[3] = 16 Then ; Fade In
                GUICtrlSetBkColor ($ahItems[$aParams[1]][$aParams[2]], $nColor_In)
                If $i = 1 Then GUICtrlSetState ($ahItems[$aParams[1]][$aParams[2]], 16)
            Else ; Fade out
                GUICtrlSetBkColor ($ahItems[$aParams[1]][$aParams[2]], $nColor_Out)
                If $i = 50 Then GUICtrlSetState ($ahItems[$aParams[1]][$aParams[2]], 32)
            EndIf
        Next
        Sleep (10)
    Next
EndFunc   ;==>BOX_RunCode

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Mat

Edit: Code update (again), edit the first 3 values to change the colours. Appears to be fading very nicely, even between Green and red etc.

Edited by Mat
Link to comment
Share on other sites

nice :

to finish, no more flickering

thx the $WS_EX_COMPOSITED = 0x2000000

GUICreate("Binary Clock", 140, 94, -1, -1, 0x00080000 + 0x00C00000,$WS_EX_COMPOSITED )

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...