Circular Clock
#1
This is a modern-looking clock that builds up the circles as it goes for seconds, minutes, and hours. I used the 4th number in the RGB commands for CIRCLE to make them a bit translucent. You can see the picture below. Like most of my clocks I added Dav's chimes to it. The clock hands and chimes are in a separate SUB if anyone wants to use it for their own clock. 
[Image: Circular-Clock-by-Sierra-Ken.jpg]


Code: (Select All)
'Circular Clock by SierraKen
'April 25, 2022
'Chimes code by Dav.

w = 180
Screen _NewImage(400, 400, 32)
Do
    _Limit 20
    t$ = Time$
    hour$ = Left$(t$, 2)
    minute$ = Mid$(t$, 4, 2)
    second$ = Right$(t$, 2)
    hour = Val(hour$)
    minute = Val(minute$)
    second = Val(second$)
    If hour < 12 Then ampm$ = "am"
    If hour > 11 Then ampm$ = "pm"
    If hour > 12 Then hour = hour - 12
    If hour = 0 Then hour = 12
    If minute < 10 Then
        zero = 1
    Else
        zero = 0
    End If
    If hour < 10 Then
        zero2 = 1
    Else
        zero2 = 0
    End If
    If second < 10 Then
        zero3 = 1
    Else
        zero3 = 0
    End If
    hr$ = Str$(hour)
    mi$ = LTrim$(Str$(minute))
    se$ = LTrim$(Str$(second))
    If zero = 1 Then mi$ = "0" + LTrim$(mi$)
    If zero2 = 1 Then hr$ = "0" + LTrim$(hr$)
    If zero3 = 1 Then se$ = "0" + LTrim$(se$)
    ti$ = hr$ + ":" + mi$ + ":" + se$ + " " + ampm$ + "   Space Bar to hear hour."
    _Title ti$
    For back = 0 To 400 Step .1
        cl = cl + .06
        Line (0, back)-(400, back), _RGB32(0, 0, cl)
    Next back
    cl = 0
    Circle (200, 200), w, _RGB32(255, 255, 255)

    For s = .1 To (second * 3) Step .1
        Circle (200, 200), s, _RGB32(127, 255, 127, 30)
    Next s
    For h = .1 To (hour * 15) Step .1
        Circle (200, 200), h, _RGB32(255, 0, 0, 30)
    Next h
    For m = .1 To (minute * 3) Step .1
        Circle (200, 200), m, _RGB32(0, 0, 255, 15)
    Next m
    clock song
    For sz = .1 To 5 Step .1
        Circle (200, 200), sz, _RGB32(0, 0, 0)
    Next sz
    _Display
    Cls
Loop Until InKey$ = Chr$(27)
End

Sub clock (song)
    _Limit 20
    a$ = InKey$
    If a$ = Chr$(27) Then End
    If a$ = " " Then song = 1
    hours = (Timer \ 3600)
    minutes = Timer \ 60 - hours * 60
    seconds = (Timer - hours * 3600 - minutes * 60)
    hours = hours + (minutes / 60) 'Code added to make hour hand move between numbers.
    ho$ = Left$(Time$, 2): hou = Val(ho$)
    min$ = Mid$(Time$, 4, 2): minu = Val(min$)
    seco$ = Right$(Time$, 2): secon = Val(seco$)

    'Seconds
    s = (60 - seconds) * 6 + 180
    x = Int(Sin(s / 180 * 3.141592) * 120) + 200
    y = Int(Cos(s / 180 * 3.141592) * 120) + 200
    For b = -5 To 5 Step .1
        Line (200 + b, 200)-(x, y), _RGB32(127, 255, 127, 30)
        Line (200, 200 + b)-(x, y), _RGB32(127, 255, 127, 30)
    Next b
    'Minutes
    m = 180 - minutes * 6
    xx = Int(Sin(m / 180 * 3.141592) * 120) + 200
    yy = Int(Cos(m / 180 * 3.141592) * 120) + 200
    For b = -5 To 5 Step .1
        Line (200 + b, 200)-(xx, yy), _RGB32(0, 0, 255, 30)
        Line (200, 200 + b)-(xx, yy), _RGB32(0, 0, 255, 30)
    Next b
    'Hours
    h = 360 - hours * 30 + 180
    xxx = Int(Sin(h / 180 * 3.141592) * 65) + 200
    yyy = Int(Cos(h / 180 * 3.141592) * 65) + 200
    For b = -5 To 5 Step .1
        Line (200 + b, 200)-(xxx, yyy), _RGB32(255, 0, 0, 30)
        Line (200, 200 + b)-(xxx, yyy), _RGB32(255, 0, 0, 30)
    Next b
    'Chimes
    If (minu = 0 And secon = 0) Or song = 1 Then
        song = 0

        'Note frequencies thanks to Dav!
        For notes = 1 To 20
            If notes = 1 Then note = 311.13 'D#
            If notes = 2 Then note = 246.94 'B
            If notes = 3 Then note = 277.18 'C#
            If notes = 4 Then note = 185.00 'F#
            If notes = 5 Then note = 0
            If notes = 6 Then note = 185.00 'F#
            If notes = 7 Then note = 277.18 'C#
            If notes = 8 Then note = 311.13 'D#
            If notes = 9 Then note = 246.94 'B
            If notes = 10 Then note = 0
            If notes = 11 Then note = 311.13 'D#
            If notes = 12 Then note = 277.18 'C3
            If notes = 13 Then note = 246.94 'B
            If notes = 14 Then note = 185.00 'F#
            If notes = 15 Then note = 0
            If notes = 16 Then note = 185.00 'F#
            If notes = 17 Then note = 277.18 'C#
            If notes = 18 Then note = 311.13 'D#
            If notes = 19 Then note = 246.94 'B
            If notes = 20 Then note = 0

            Do
                'queue some sound
                Do While _SndRawLen < 0.5 'you may wish to adjust this
                    sample = Sin(ttt * note * Atn(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
                    sample = sample * Exp(-ttt * 3) 'fade out eliminates clicks after sound
                    _SndRaw sample
                    ttt = ttt + 1 / _SndRate 'sound card sample frequency determines time
                Loop
                'do other stuff, but it may interrupt sound
            Loop While ttt < 1 'play for 1 second
            Do While _SndRawLen > 0 'Finish any left over queued sound!
            Loop
            ttt = 0
        Next notes
        hour2 = hou
        If hour2 > 12 Then hour2 = hour2 - 12
        If hour2 = 0 Then hour2 = 12
        For chimes = 1 To hour2
            ttt = 0
            Do
                'queue some sound
                Do While _SndRawLen < 0.1 'you may wish to adjust this
                    sample = Sin(ttt * 240 * Atn(1) * 8) '340Hz sine wave (ttt * 440 * 2p)
                    sample = sample * Exp(-ttt * 3) 'fade out eliminates clicks after sound
                    _SndRaw sample
                    ttt = ttt + 1 / _SndRate 'sound card sample frequency determines time
                Loop
                'do other stuff, but it may interrupt sound
            Loop While ttt < 2 'play for 2 seconds
            Do While _SndRawLen > 0 'Finish any left over queued sound!
            Loop
        Next chimes
    End If
    two:
End Sub
Reply
#2
That IS a modern look and so simple too. Smile
b = b + ...
Reply
#3
I like the design. Very nice. All done with some nice compact code too.
Reply
#4
Thanks hanness. I use a lot of that clock code in many other clocks of mine.
Reply




Users browsing this thread: 4 Guest(s)