Jump to content

ascii art clock


Gianni
 Share

Recommended Posts

Very cool compact code :thumbsup:

I added $WS_EX_COMPOSITED and the GUI doesn't flicker anymore on my Win8.1 notebook.

What bothers me is that AM / PM moves on each second.

 

 

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

5 hours ago, czardas said:

Now can you make one that's round. Only joking (unless of course you want to :D). Very nice idea.

thanks czardas, .... a round ascii clock? ...

4 hours ago, UEZ said:

Very cool compact code :thumbsup:

I added $WS_EX_COMPOSITED and the GUI doesn't flicker anymore on my Win8.1 notebook.

What bothers me is that AM / PM moves on each second.

thanks UEZ,  $WS_EX_COMPOSITED... interesting extended Style.
Fixed the am/pm (it doesn't bothers any more....). updated first post.

 

Thanks to all those who have clicked "like this" :P

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

2 hours ago, Chimp said:

thanks czardas, .... a round ascii clock? ...

thanks UEZ,  $WS_EX_COMPOSITED... interesting extended Style.
Fixed the am/pm (it doesn't bothers any more....). updated first post.

 

Thanks to all those who have clicked "like this" :P

:thumbsup:

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I assume czardas means something like this here: http://codegolf.stackexchange.com/questions/10759/build-an-analog-clock 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

A practical problem is how to freely position individual ascii chars on label (using monospaced font as courier new) at a given row and a given column leaving unchanged what is already printed on the label.
for example it would be useful a functio like Print($hLabel, $sChar, $iCol, $iRow)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Here a version for a ASCII Analogue Clock - (GDI+ free version :sweating:):

;coded by UEZ build 2016-02-23
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $iWm = 29, $iHm = 19, $imX = Ceiling($iWm / 2), $imY = Ceiling($iHm / 2), $fRad = ACos(-1) / 180
Global $aArrayMatrix[$iHm + 1][$iWm + 1], $aPic[$iHm], $i, $f = $iHm

Global Const $iW = Ceiling($iWm * $f * 2 / 3) - $iWm / 2, $iH = $iHm * $f, $iW2 = $iW / 2
Global Const $hGUI = GUICreate("ASCII Analogue Clock by UEZ v1.1", $iW, $iH, -1, -1, -1, $WS_EX_COMPOSITED)

For $i = 0 To $iHm - 1
    $aPic[$i] = GUICtrlCreateLabel("", 0, $i * $f, $iW, $f)
    GUICtrlSetFont(-1, $f * 0.825, 800, 0, "Courier new", 5)
    GUICtrlSetBkColor(-1, Sin($i * $iHm / 0x150) * 0x100 + 0xFF00)
    GUICtrlSetColor(-1, 0x0)
Next
GUISetState()

AnimClock()

GUIRegisterMsg($WM_TIMER, "AnimClock")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", 1000, "int", 0)


Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_TIMER, "")
            GUIDelete()
            Exit
    EndSwitch
Until False

Func AnimClock()
    Local $i, $iX, $iY, $sx, $imm = $iWm, $sBg = " "
    Local $aSlope_Hr = CalcSlope(   $imY,   $imX,   $imY + Cos((-90 + 30 * (Mod(@HOUR, 12) + @MIN / 60)) * $fRad) * $imX * 0.45, $imX + Sin((-90 + 30 * (Mod(@HOUR, 12) + @MIN / 60)) * $fRad) * $imY * 0.45)
    Local $aSlope_Min = CalcSlope(  $imY,   $imX,   $imY + Cos((-90 + 6 * @MIN) * $fRad) * $imX * 0.65,                         $imX + Sin((-90 + 6 * @MIN) * $fRad) * $imY * 0.65)
    Local $aSlope_Sec = CalcSlope(  $imY,   $imX,   $imY + Cos((-90 + 6 * @SEC) * $fRad) * $imX * 0.85,                         $imX + Sin((-90 + 6 * @SEC) * $fRad) * $imY * 0.85)
    Local $aSlope_Sec2 = CalcSlope( $imY,   $imX,   $imY + Cos((-270 + 6 * @SEC) * $fRad) * $imX * 0.35,                        $imX + Sin((-270 + 6 * @SEC) * $fRad) * $imY * 0.35)
    Local Const $fSy_hr = $aSlope_Hr[0] / $imm
    Local Const $fSx_hr = $aSlope_Hr[1] / $imm
    Local Const $fSy_min = $aSlope_Min[0] / $imm
    Local Const $fSx_min = $aSlope_Min[1] / $imm
    Local Const $fSy_sec = $aSlope_Sec[0] / $imm
    Local Const $fSx_sec = $aSlope_Sec[1] / $imm
    Local Const $fSy_sec2 = $aSlope_Sec2[0] / $imm
    Local Const $fSx_sec2 = $aSlope_Sec2[1] / $imm
    For $i = $imm To 0 Step - 1
        $aArrayMatrix[$imY - 1 + Round($i * $fSy_min)][$imX - 1 + Round($i * $fSx_min)] = ChrW(9618)
        $aArrayMatrix[$imY - 1 + Round($i * $fSy_hr) ][$imX - 1 + Round($i * $fSx_hr)] = ChrW(9617)
    Next
    For $i = $imm To 0 Step - 1 ;write seconds to the top
        $aArrayMatrix[$imY - 1 + Round($i * $fSy_sec)][$imX - 1 + Round($i * $fSx_sec)] = ChrW(9619)
        $aArrayMatrix[$imY - 1 + Round($i * $fSy_sec2)][$imX - 1 + Round($i * $fSx_sec2)] = ChrW(9619)
    Next
    $aArrayMatrix[$iHm - 1][0] = "U"
    $aArrayMatrix[$iHm - 1][1] = "E"
    $aArrayMatrix[$iHm - 1][2] = "Z"
    $aArrayMatrix[$iHm - 1][3] = ChrW(9786)
    $aArrayMatrix[$imY + 4][$imX - 1] = @HOUR > -1 And @HOUR < 12 ? "A" : "P"
    $aArrayMatrix[$imY + 4][$imX] = "M"
    For $i = 0 To 360 Step 30
        $aArrayMatrix[$imY - 1 + Round(Cos($i * $fRad) * $imY * 0.92)][$imX - 1 + Round(Sin($i * $fRad) * $imX * 0.92)] = "."
    Next
    For $iY = 0 To $iHm - 1
        $sx = ""
        For $iX = 0 To $iWm - 1
            $t = $aArrayMatrix[$iY][$iX]
            $t = ($t = "") ? $sBg : $t
            Switch $iX
                Case 0
                    Switch $iY
                        Case $imY - 1
                            $t = "9"
                    EndSwitch
                Case $iWm - 1
                    Switch $iY
                        Case $imY - 1
                            $t = "3"
                    EndSwitch
                Case $imX - 1
                    Switch $iY
                        Case 0
                            $t = "12"
                        Case $iHm - 1
                            $t = "6"
                        Case $iMy - 1
                            $t = ChrW(8986)
                    EndSwitch
            EndSwitch
            $sx &= $t
            $aArrayMatrix[$iY][$iX] = $sBg
        Next
        GUICtrlSetData($aPic[$iY], $sx)
    Next
EndFunc

Func CalcSlope($iX1, $iY1, $iX2, $iY2)
    Local $aSlope[2] = [$iY2 - $iY1, $iX2 - $iX1]
    Return $aSlope
EndFunc

 

Edited by UEZ
added v1.1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

4 hours ago, UEZ said:

Here a version for a ASCII Analogue Clock - (GDI+ free version :sweating:):

.....

Hi UEZ, nice version !.

you used a matrix of labels as chars container to build and position clock hands in fixed position... interesting solution.
(as you can see is harder using simple ascii chars than GDI+... :))

Nice analog Clock BTW :thumbsup:


I approched the problem in a different way, I used just one big label as a blackboard where i can write at any location using the PrePrint() / Print() functions that allows me to specifing the wanted horizontal and vertical locations where to print chars or strings as well. Down here there is my experimental version:

On 20/2/2016 at 9:48 PM, czardas said:

I guess if you used a really small font you could do an almost round ascii clock. :idea:

... here we go... :)

 

#include <GUIConstants.au3>
HotKeySet("{ESC}", "EndOfTime")
Global $sBuffer = _StringReplicate(" ", 80) & @CRLF ; a string of 80 blank spaces + @crlf
$sBuffer = _StringReplicate($sBuffer, 24) ; 25 of above lines

Global $MyGui = GUICreate("", 400, 300, -1, -1, $WS_POPUPWINDOW, BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE, $WS_EX_COMPOSITED, $WS_EX_LAYERED))
Global $hClock = GUICtrlCreateLabel("", 0, 0, 400, 400, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 7, 0, 0, "Courier new")
GUICtrlSetData($hClock, $sBuffer)
GUISetState()

;          X,  Y, Ray, Char, Step
TextCircle(40, 13, 12, "", 12) ; draw Hours on clock
TextCircle(40, 13, 11, ".", 60) ; draw Mins on clock
PrePrint("O", 40, 13) ; center of the clock
While 1
    $iHour = @HOUR
    $iMin = @MIN
    $iSec = @SEC
    For $ii = 1 To 7 ; draw clock hands
        TextPosOnCircle(40, 13, 8 - $ii, 'H', 12, $iHour) ; 1 houur
        TextPosOnCircle(40, 13, 9 - $ii, 'm', 60, $iMin) ; 1 min
        TextPosOnCircle(40, 13, 10 - $ii, '.', 60, $iSec) ; 1 min
    Next
    PrePrint($iHour & ":" & $iMin & ":" & $iSec, 36, 19)
    Print(); show whole buffer on the label
    Sleep(1000)
    For $ii = 1 To 7 ; erase clock hands
        TextPosOnCircle(40, 13, 8 - $ii, ' ', 12, $iHour) ; 1 houur
        TextPosOnCircle(40, 13, 9 - $ii, ' ', 60, $iMin) ; 1 min
        TextPosOnCircle(40, 13, 10 - $ii, ' ', 60, $iSec) ; 1 min
    Next
WEnd

; From HtabVtab (1 based) to Absolute
; -----------------------------------
Func GetAbsPos($iHtab = 1, $iVtab = 1, $iScreenWidth = 80)
    Return ($iVtab - 1) * ($iScreenWidth + 2) + $iHtab ; position within the String buffer
EndFunc   ;==>GetAbsPos

Func PrePrint($sString = "", $iHtab = 1, $iVtab = 1) ; Print to String Buffer only
    $sBuffer = StringReplace($sBuffer, GetAbsPos($iHtab, $iVtab), $sString)
EndFunc   ;==>PrePrint

Func Print() ; Copy String Buffer to Label
    GUICtrlSetData($hClock, $sBuffer)
EndFunc   ;==>Print

; returns one or more chars replicated n times
; Example: ConsoleWrite(_StringReplicate('*', 5) & @CRLF)
Func _StringReplicate($sChars = "", $iRepeats = 0)
    $sChars = String($sChars)
    $iRepeats = Int(Abs(Number($iRepeats)))
    Return StringReplace(StringFormat('%' & $iRepeats & 's', ""), " ", $sChars)
EndFunc   ;==>_StringReplicate

; Drawing a circle using SIN and COS
Func TextCircle($cx = 40, $cy = 12, $r = 12, $sChar = "", $iStep = 12)
    Local $pi = 3.14159, $nr = 0
    For $i = 1.56 To (2 * $pi) + 1.56 Step ($pi * 2) / $iStep
        $x = Cos($i) * $r * 3 ; compensate horizontally
        $y = Sin($i) * $r
        PrePrint(($sChar = "" ? $nr : $sChar), Int($cx - $x), Int($cy - $y))
        $nr += 1
    Next
    Print()
EndFunc   ;==>TextCircle

; position a char along a circle to a wanted point
Func TextPosOnCircle($cx, $cy, $r, $sChar, $iStep, $iValue)
    Local $pi = 3.14159
    Local $iStepper = (($pi * 2) / $iStep)
    $i = 1.56 + ((($iValue + 1) * $iStepper) - $iStepper)
    $x = Cos($i) * $r * 3 ; compensate harizontal
    $y = Sin($i) * $r
    PrePrint($sChar, Int($cx - $x), Int($cy - $y))
    ; Print()
EndFunc   ;==>TextPosOnCircle

Func EndOfTime()
    If WinActive("[ACTIVE]") = $MyGui Then Exit
EndFunc   ;==>EndOfTime

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

17 hours ago, Chimp said:

Hi UEZ, nice version !.

you used a matrix of labels as chars container to build and position clock hands in fixed position... interesting solution.
(as you can see is harder using simple ascii chars than GDI+... :))

Nice analog Clock BTW :thumbsup:


I approched the problem in a different way, I used just one big label as a blackboard where i can write at any location using the PrePrint() / Print() functions that allows me to specifing the wanted horizontal and vertical locations where to print chars or strings as well. Down here there is my experimental version:

... here we go... :)

 

 

 

Well, I used a 2D array which is similar to a graphic canvas where you have width and height and calculated the "line" from the center to the appropriate position. My first idea was to draw the clock first to GDI+ and transform afterwards the bitmap to ASCII chars but it was too complicated.

Many ways lead to Rome and probably your way is much shorter than my way. ;)

Your version looks much better. :thumbsup:

 

Edit: updated my version to v1.1 (see #10)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...