Jump to content

Fibonacci Clock


Melba23
 Share

Recommended Posts

Very nice clocks guys. :)
I have a another way to calculate the colors for the clock.
I use the Bit Operations. I hope it's okay that I used UEZ script as submission.

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

$iMargin_X = 10
$iMargin_Y = 10
$iMargin_Inter = 5
$iSize = 50
$iButton_Level = ($iSize * 5) + $iMargin_Inter + 20

$hGUI = GUICreate("Fibonacci Clock", ($iSize * 8) + ($iMargin_X * 2), $iButton_Level + 100)
GUISetBkColor(0xC4C4C4)

$cBack = GUICtrlCreateLabel("", $iMargin_X - $iMargin_Inter, $iMargin_Y - $iMargin_Inter, _
        ($iSize * 8) + ($iMargin_Inter * 2), ($iSize * 5) + $iMargin_Inter)
GUICtrlSetBkColor($cBack, 0x000000)

$cLabel_1A = GUICtrlCreateLabel("1", $iMargin_X + ($iSize * 2), $iMargin_Y, $iSize - $iMargin_Inter, $iSize - $iMargin_Inter)
$cLabel_1B = GUICtrlCreateLabel("1", $iMargin_X + ($iSize * 2), $iMargin_Y + $iSize, $iSize - $iMargin_Inter, $iSize - $iMargin_Inter)
$cLabel_2 = GUICtrlCreateLabel("2", $iMargin_X, $iMargin_Y, ($iSize * 2) - $iMargin_Inter, ($iSize * 2) - $iMargin_Inter)
$cLabel_3 = GUICtrlCreateLabel("3", $iMargin_X, $iMargin_Y + ($iSize * 2), ($iSize * 3) - $iMargin_Inter, ($iSize * 3) - $iMargin_Inter)
$cLabel_5 = GUICtrlCreateLabel("5", $iMargin_X + ($iSize * 3), $iMargin_Y, $iSize * 5, ($iSize * 5) - $iMargin_Inter)

$cUserSet = GUICtrlCreateButton("Set User Time", $iMargin_X, $iButton_Level, 100, 30)
$cUserHour = GUICtrlCreateCombo("", $iMargin_X + 120, $iButton_Level, 40, 20)
GUICtrlSetData($cUserHour, "00|01|02|03|04|05|06|07|08|09|10|11|12")
$cUserMin = GUICtrlCreateCombo("", $iMargin_X + 160, $iButton_Level, 40, 20)
GUICtrlSetData($cUserMin, "00|05|10|15|20|25|30|35|40|45|50|55")
$cReset = GUICtrlCreateButton("Reset Current Time", $iMargin_X, $iButton_Level + 50, 120, 30)

GUICtrlCreateLabel("Hours:" & @CRLF & @CRLF & "Mins:" & @CRLF & @CRLF & "Both:", 250, $iButton_Level, 150, 80)
GUICtrlCreateLabel("", 300, $iButton_Level, 50, 20)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlCreateLabel("", 300, $iButton_Level + 25, 50, 20)
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlCreateLabel("", 300, $iButton_Level + 50, 50, 20)
GUICtrlSetBkColor(-1, 0x0000FF)

GUISetState()

_Reset()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cReset
            _Reset()
        Case $cUserSet
            $iHour = GUICtrlRead($cUserHour)
            $iMin = GUICtrlRead($cUserMin)
            _Set_Clock($iHour, $iMin)
    EndSwitch

WEnd

Func _Reset()

    $sDTG = _NowCalc()
    $iHour = StringRegExpReplace($sDTG, "^.*\s(\d\d):.*", "$1")
    $iMin = StringRegExpReplace($sDTG, "^.*:(\d\d):.*", "$1")

    _Set_Clock($iHour, $iMin)

EndFunc   ;==>_Reset

Func _Set_Clock($iH, $iM)
    Local Static $aiColor[4] = [0xC4C4C4, 0x00FF00, 0xFF0000, 0x0000FF]
    Local $iColor = _FibColor($iH, $iM)

    GUICtrlSetBkColor($cLabel_1B, $aiColor[BitAND($iColor, 3)])
    GUICtrlSetBkColor($cLabel_1A, $aiColor[BitShift(BitAND($iColor, 12), 2)])
    GUICtrlSetBkColor($cLabel_2, $aiColor[BitShift(BitAND($iColor, 48), 4)])
    GUICtrlSetBkColor($cLabel_3, $aiColor[BitShift(BitAND($iColor, 192), 6)])
    GUICtrlSetBkColor($cLabel_5, $aiColor[BitShift(BitAND($iColor, 768), 8)])

EndFunc   ;==>_Set_Clock

Func _FibColor($iHour, $iMin)
    Return BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitAND(_DecToFib(Mod($iHour, 13)), 16) And True, -2), BitAND(_DecToFib(Mod($iHour, 13)), 8) And True), -2), BitAND(_DecToFib(Mod($iHour, 13)), 4) And True), -2), BitAND(_DecToFib(Mod($iHour, 13)), 2) And True), -2), BitAND(_DecToFib(Mod($iHour, 13)), 1) And True), -1), BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitAND(_DecToFib(Mod(Ceiling($iMin / 5), 12)), 16) And True, -2), BitAND(_DecToFib(Mod(Ceiling($iMin / 5), 12)), 8) And True), -2), BitAND(_DecToFib(Mod(Ceiling($iMin / 5), 12)), 4) And True), -2), BitAND(_DecToFib(Mod(Ceiling($iMin / 5), 12)), 2) And True), -2), BitAND(_DecToFib(Mod(Ceiling($iMin / 5), 12)), 1) And True))
EndFunc   ;==>_FibColor

Func _DecToFib($iNum)
    Return BitOR(BitShift(BitOR(BitShift(BitOR(BitShift(BitOR(BitShift((BitAND($iNum, 4) And BitAND($iNum, 1)) Or (BitAND($iNum, 4) And BitAND($iNum, 2)) Or BitAND($iNum, 8), -1), (BitAND($iNum, 4) And Not BitAND($iNum, 2) And Not BitAND($iNum, 1)) Or BitAND($iNum, 8)), -1), (Not BitAND($iNum, 4) And BitAND($iNum, 2)) Or (BitAND($iNum, 2) And BitAND($iNum, 1)) Or (BitAND($iNum, 8) And BitAND($iNum, 4))), -1), (Not BitAND($iNum, 4) And BitAND($iNum, 1)) Or (BitAND($iNum, 4) And Not BitAND($iNum, 1))), -1), BitAND($iNum, 8) And BitAND($iNum, 4))
EndFunc   ;==>_DecToFib

Cythor :)

Link to comment
Share on other sites

 Any thoughts out there on how to measure the passing of each minute rather than the current changes on each 5 minute block?

​You only need to add between 0 and 4 minutes to the current time. There are a few possibilities without altering the design: you could highlight squares or use more colours. Dark red, dark blue, dark green or dark white (grey) to add an increment to minutes.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

UEZ,

Your version works nicely for me.

czardas,

Highlighting certain squares was one of the ways I was considering - I will see what I can do this afternoon.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi,

This time I really do mean for this to be my last contribution (but who knows?):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <Date.au3>

$iMargin_X = 10
$iMargin_Y = 10
$iMargin_Inter = 5
$iSize = 50
$iLabel_Level = ($iSize * 5) + $iMargin_Inter + 20

$hGUI = GUICreate("Fibonacci Clock", ($iSize * 8) + ($iMargin_X * 2), $iLabel_Level + 50)
GUISetBkColor(0xC4C4C4)

$cBack = GUICtrlCreateLabel("", $iMargin_X - $iMargin_Inter, $iMargin_Y - $iMargin_Inter, _
        ($iSize * 8) + ($iMargin_Inter * 2), ($iSize * 5) + $iMargin_Inter)
GUICtrlSetBkColor($cBack, 0xA0A0A0)

$cHiLite_1 = GUICtrlCreateLabel("", $iMargin_X + ($iSize * 2) - $iMargin_Inter, $iMargin_Y - $iMargin_Inter, $iSize + $iMargin_Inter, $iSize + $iMargin_Inter)
GUICtrlSetBkColor($cHiLite_1, $GUI_BKCOLOR_TRANSPARENT)
$cHiLite_2 = GUICtrlCreateLabel("", $iMargin_X - $iMargin_Inter, $iMargin_Y - $iMargin_Inter, ($iSize * 2) + $iMargin_Inter, ($iSize * 2) + $iMargin_Inter)
GUICtrlSetBkColor($cHiLite_2, $GUI_BKCOLOR_TRANSPARENT)
$cHiLite_3 = GUICtrlCreateLabel("", $iMargin_X - $iMargin_Inter, $iMargin_Y + ($iSize * 2) - $iMargin_Inter, ($iSize * 3) + $iMargin_Inter, ($iSize * 3) + $iMargin_Inter)
GUICtrlSetBkColor($cHiLite_3, $GUI_BKCOLOR_TRANSPARENT)

$cLabel_1A = GUICtrlCreateLabel("", $iMargin_X + ($iSize * 2), $iMargin_Y, $iSize - $iMargin_Inter, $iSize - $iMargin_Inter)
$cLabel_1B = GUICtrlCreateLabel("", $iMargin_X + ($iSize * 2), $iMargin_Y + $iSize, $iSize - $iMargin_Inter, $iSize - $iMargin_Inter)
$cLabel_2 = GUICtrlCreateLabel("", $iMargin_X, $iMargin_Y, ($iSize * 2) - $iMargin_Inter, ($iSize * 2) - $iMargin_Inter)
$cLabel_3 = GUICtrlCreateLabel("", $iMargin_X, $iMargin_Y + ($iSize * 2), ($iSize * 3) - $iMargin_Inter, ($iSize * 3) - $iMargin_Inter)
$cLabel_5 = GUICtrlCreateLabel("", $iMargin_X + ($iSize * 3), $iMargin_Y, $iSize * 5, ($iSize * 5) - $iMargin_Inter)

GUICtrlCreateLabel("Hours:", $iMargin_X, $iLabel_Level + 10, 100, 15)
GUICtrlCreateLabel("AM", $iMargin_X + 40, $iLabel_Level, 25, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlCreateLabel("PM", $iMargin_X + 40, $iLabel_Level + 20, 25, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0x00FFFF)
GUICtrlCreateLabel("Min x 5:", $iMargin_X + 110, $iLabel_Level + 10, 100, 15)
GUICtrlCreateLabel("AM", $iMargin_X + 155, $iLabel_Level, 25, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlCreateLabel("PM", $iMargin_X + 155, $iLabel_Level + 20, 25, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFF00FF)
GUICtrlCreateLabel("+", $iMargin_X + 185, $iLabel_Level + 10, 15, 15)
GUICtrlCreateLabel("", $iMargin_X + 195, $iLabel_Level + 10, 25, 15)
GUICtrlSetBkColor(-1, 0x707070)
GUICtrlCreateLabel("", $iMargin_X + 197, $iLabel_Level + 12, 21, 11)
GUICtrlSetBkColor(-1, 0xC4C4C4)
GUICtrlCreateLabel("Both:", $iMargin_X + 240, $iLabel_Level + 10, 100, 15)
GUICtrlCreateLabel("AM", $iMargin_X + 270, $iLabel_Level, 25, 15, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x0000FF)
GUICtrlCreateLabel("PM", $iMargin_X + 270, $iLabel_Level + 20, 25, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFFFF00)

$cShow = GUICtrlCreateCheckbox("Show time", 340, $iLabel_Level - 2, 60, 20, $BS_PUSHLIKE)
$cShow_Label = GUICtrlCreateLabel("", 340, $iLabel_Level + 22, 60, 20, $SS_CENTER)

GUISetState()

$iPrevMin = -1
$bShow = False

_Set_Clock()
_Set_Min(Mod(@MIN, 5))

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cShow
            $bShow = Not($bShow)
            If $bShow Then
                GUICtrlSetData($cShow_Label, @HOUR & ":" & @MIN)
                GUICtrlSetData($cShow, "Hide time")
            Else
                GUICtrlSetData($cShow_Label, "")
                GUICtrlSetData($cShow, "Show time")
            EndIf
    EndSwitch

    $iCurrMin = @MIN
    If $iCurrMin <> $iPrevMin Then
        If $bShow Then
            GUICtrlSetData($cShow_Label, @HOUR & ":" & @MIN)
        EndIf
        $iPrevMin = $iCurrMin
        _Set_Min(Mod($iCurrMin, 5))
    EndIf

WEnd

Func _Set_Min($iM)

    GUICtrlSetBkColor($cHiLite_1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($cHiLite_2, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($cHiLite_3, $GUI_BKCOLOR_TRANSPARENT)
    Switch $iM
        Case 4
            GUICtrlSetBkColor($cHiLite_3, 0x707070)
            GUICtrlSetBkColor($cHiLite_1, 0x707070)
        Case 3
            GUICtrlSetBkColor($cHiLite_3, 0x707070)
        Case 2
            GUICtrlSetBkColor($cHiLite_2, 0x707070)
        Case 1
            GUICtrlSetBkColor($cHiLite_1, 0x707070)
        Case 0
            _Set_Clock()
    EndSwitch

EndFunc   ;==>_Set_Min

Func _Set_Clock()

    $sDTG = _NowCalc()
    $iH = Int(StringRegExpReplace($sDTG, "^.*\s(\d\d):.*", "$1"))
    $iHour_Col = 0xFF0000
    $iMin_Colour = 0x00FF00
    $iBoth_Colour = 0x0000FF
    If $iH > 11 Then
        $iHour_Col = 0x00FFFF
        $iMin_Colour = 0xFF00FF
        $iBoth_Colour = 0xFFFF00
        $iH = $iH - 12
    EndIf
    $iM = Int(StringRegExpReplace($sDTG, "^.*:(\d\d):.*", "$1") / 5)

    GUICtrlSetBkColor($cLabel_1A, 0xC4C4C4)
    GUICtrlSetBkColor($cLabel_1B, 0xC4C4C4)
    GUICtrlSetBkColor($cLabel_2, 0xC4C4C4)
    GUICtrlSetBkColor($cLabel_3, 0xC4C4C4)
    GUICtrlSetBkColor($cLabel_5, 0xC4C4C4)

    $iState_1A = 0
    $iState_1B = 0
    $iState_2 = 0
    $iState_3 = 0
    $iState_5 = 0

    While $iH
        Switch $iH
            Case 5 To 12
                If Not $iState_5 Then
                    $iH -= 5
                    GUICtrlSetBkColor($cLabel_5, $iHour_Col)
                    $iState_5 = 1
                Else
                    ContinueCase
                EndIf
            Case 3 To 12
                If Not $iState_3 Then
                    $iH -= 3
                    GUICtrlSetBkColor($cLabel_3, $iHour_Col)
                    $iState_3 = 1
                Else
                    ContinueCase
                EndIf
            Case 2 To 12
                If Not $iState_2 Then
                    $iH -= 2
                    GUICtrlSetBkColor($cLabel_2, $iHour_Col)
                    $iState_2 = 1
                Else
                    ContinueCase
                EndIf
            Case Else
                If $iState_1A Then
                    $iH -= 1
                    GUICtrlSetBkColor($cLabel_1B, $iHour_Col)
                    $iState_1B = 1
                Else
                    $iH -= 1
                    GUICtrlSetBkColor($cLabel_1A, $iHour_Col)
                    $iState_1A = 1
                EndIf
        EndSwitch
    WEnd

    While $iM

        Switch $iM
            Case 5 To 12
                $bContinueCase = False
                Switch $iState_5
                    Case 0
                        $iM -= 5
                        GUICtrlSetBkColor($cLabel_5, $iMin_Colour)
                        $iState_5 = 2
                    Case 1
                        $iM -= 5
                        GUICtrlSetBkColor($cLabel_5, $iBoth_Colour)
                        $iState_5 = 2
                    Case 2
                        $bContinueCase = True
                EndSwitch

                If $bContinueCase Then ContinueCase
            Case 3 To 12
                $bContinueCase = False
                Switch $iState_3
                    Case 0
                        $iM -= 3
                        GUICtrlSetBkColor($cLabel_3, $iMin_Colour)
                        $iState_3 = 2
                    Case 1
                        $iM -= 3
                        GUICtrlSetBkColor($cLabel_3, $iBoth_Colour)
                        $iState_3 = 2
                    Case 2
                        $bContinueCase = True
                EndSwitch
                If $bContinueCase Then ContinueCase
            Case 2 To 12
                $bContinueCase = False
                Switch $iState_2
                    Case 0
                        $iM -= 2
                        GUICtrlSetBkColor($cLabel_2, $iMin_Colour)
                        $iState_2 = 2
                    Case 1
                        $iM -= 2
                        GUICtrlSetBkColor($cLabel_2, $iBoth_Colour)
                        $iState_2 = 2
                    Case 2
                        $bContinueCase = True
                EndSwitch
                If $bContinueCase Then ContinueCase
            Case Else
                Switch $iState_1A
                    Case 2
                        $iM -= 1
                        If $iState_1B Then
                            GUICtrlSetBkColor($cLabel_1B, $iBoth_Colour)
                        Else
                            GUICtrlSetBkColor($cLabel_1B, $iMin_Colour)
                        EndIf
                    Case 1
                        $iM -= 1
                        If $iState_1B = 0 Then
                            GUICtrlSetBkColor($cLabel_1B, $iMin_Colour)
                            $iState_1B = 1
                        Else
                            GUICtrlSetBkColor($cLabel_1A, $iBoth_Colour)
                            $iState_1A = 2
                        EndIf
                    Case Else
                        $iM -= 1
                        GUICtrlSetBkColor($cLabel_1A, $iMin_Colour)
                        $iState_1A = 1
                EndSwitch
        EndSwitch

    WEnd

EndFunc   ;==>_Set_Clock

The changes - AM/PM and single minute timing - should be easy to spot.

M23

Edited by Melba23
Code updated

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

czardas,

I see what you mean - perhaps one more version when I find the time...

M23

Edit: Code above updated.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...