
-----------------------------------
zylum
Sun Feb 22, 2004 12:01 am

nifty analog clock
-----------------------------------
here's a simple procedure that draws an analog clock. you can set the length of each hand and it will automatically adjust.  the first parameter is for the hour hand, the second is for the minute hand and the last is for the second hand...


procedure displayClock (hourHand, minuteHand, secondHand : int)
    setscreen ("offscreenonly")
    const PI := 3.14159
    var whatTime : string
    var whatDate : string
    var hour, minute, second : int
    var x, y, x2, y2 : int
    var ang : real
    loop
        date (whatDate)
        locate (1, 1)
        put whatDate
        time (whatTime)
        hour := strint (whatTime (1 .. 2))
        hour := hour mod 12
        minute := strint (whatTime (4 .. 5))
        second := strint (whatTime (7 .. 8))
        %hour hand
        ang := ((hour + (minute / 60)) / 12) * 360 - 90
        x := round (cos (-ang * (PI / 180)) * hourHand + maxx div 2)
        y := round (sin (-ang * (PI / 180)) * hourHand + maxy div 2)
        drawline (maxx div 2, maxy div 2, x, y, 7)
        %minute hand
        ang := (minute / 60) * 360 - 90
        x := round (cos (-ang * (PI / 180)) * minuteHand + maxx div 2)
        y := round (sin (-ang * (PI / 180)) * minuteHand + maxy div 2)
        drawline (maxx div 2, maxy div 2, x, y, 7)
        %second hand
        ang := (second / 60) * 360 - 90
        x := round (cos (-ang * (PI / 180)) * secondHand + maxx div 2)
        y := round (sin (-ang * (PI / 180)) * secondHand + maxy div 2)
        drawline (maxx div 2, maxy div 2, x, y, 7)
        %draw face
        for i : -90 .. 270 by 6
            if i mod 15 = 0 then
                x := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand))) + maxx div 2)
                y := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand))) + maxy div 2)
                x2 := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 10) + maxx div 2)
                y2 := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 10) + maxy div 2)
            else
                x := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 5) + maxx div 2)
                y := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 5) + maxy div 2)
                x2 := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 10) + maxx div 2)
                y2 := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand)) + 10) + maxy div 2)
            end if
            drawline (x, y, x2, y2, 7)
        end for
        drawoval (maxx div 2, maxy div 2, max (hourHand, max (minuteHand, secondHand)) + 10, max (hourHand, max (minuteHand, secondHand)) + 10, 7)
        View.Update
        cls
    end loop
end displayClock

displayClock (40, 70, 80)



- zylum

-----------------------------------
recneps
Sun Feb 22, 2004 11:08 am


-----------------------------------
Purdy, but could use some numbers and i think it moves slower than 1 move per second on my comp..? :)

-----------------------------------
jonos
Sun Feb 22, 2004 11:24 am


-----------------------------------
thats really nice, it works perfectly on my computer, even has the right time!!! wasn't expecting that

-----------------------------------
zylum
Sun Feb 22, 2004 12:28 pm


-----------------------------------
lol, well of course it has the right time, it gets the values from your system clock.  :wink:

-----------------------------------
jonos
Mon Feb 23, 2004 7:37 am


-----------------------------------
what did you use to get the system clock time? i couldn't find it in the reference

-----------------------------------
apomb
Mon Feb 23, 2004 3:53 pm


-----------------------------------
umm well to get the system clock time by using
var whatTime : string
loop
    time (whatTime)
    put whatTime
    delay (1000)
    cls
end loop 

and Zylum very nice program

-----------------------------------
jonos
Mon Feb 23, 2004 4:02 pm


-----------------------------------
thanks, so its just the a time() function.

-----------------------------------
apomb
Tue Feb 24, 2004 1:24 pm


-----------------------------------
yep... pretty simple eh? i think its in the reference... if you want a complete description. It also only works in the newest version .. so you should get yourself that if you dont already have it
