Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
nifty analog clock
Author Message
zylum

Posted: Sun Feb 22, 2004 12:01 am   Post subject: 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...

 code: 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

Posted: Sun Feb 22, 2004 11:08 am   Post subject: (No subject)

Purdy, but could use some numbers and i think it moves slower than 1 move per second on my comp..?
jonos

Posted: Sun Feb 22, 2004 11:24 am   Post subject: (No subject)

thats really nice, it works perfectly on my computer, even has the right time!!! wasn't expecting that
zylum

Posted: Sun Feb 22, 2004 12:28 pm   Post subject: (No subject)

lol, well of course it has the right time, it gets the values from your system clock.
jonos

Posted: Mon Feb 23, 2004 7:37 am   Post subject: (No subject)

what did you use to get the system clock time? i couldn't find it in the reference
apomb

Posted: Mon Feb 23, 2004 3:53 pm   Post subject: (No subject)

umm well to get the system clock time by using
 code: var whatTime : string loop     time (whatTime)     put whatTime     delay (1000)     cls end loop

and Zylum very nice program
jonos

Posted: Mon Feb 23, 2004 4:02 pm   Post subject: (No subject)

thanks, so its just the a time() function.
apomb

Posted: Tue Feb 24, 2004 1:24 pm   Post subject: (No subject)

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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 8 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: