Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Making a clock....

Author
Message
hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 25th Nov 2008 09:31
I'm trying to make an analogue clock, And I'm trying to figure out how to make my hand (The line) turn to the variable Time1, If that's even possible. I'm not quite sure what to do and how (It's taken me almost an hour to figure out how to get the line to point up). Can anyone help me out?

Here's the code.

Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 25th Nov 2008 17:00
It depends on how you are going to do the hand,

If you were going to do it with a simple line then it would be fairly simple, if you are using a sprite im not quite sure how you would do it.

if you were going to do it with a line then you would do it something like this:



but this will only do the seconds hand, from this the minute and hour hand shouldnt be too hard to work out.

Im sorry if its not very clear, say if you need more help.

hope this helps,,,

codeeater
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 25th Nov 2008 17:26
Personally, I have always been fond of polar coordinates.

Polar coordinates, unlike the Cartesian coordinates normally used (that have an X coordinate and a Y coordinate), utilize a distance and an angle. The beauty of this is that you only need to change the angle, and it all works out.

So it would look something like this:
R=5
Theta=45

Those are the arrays for a line of length 5 at 45 degrees. But how do you use that if DBC doesn't know how to handle polar coordinates you ask? Some simple trig (don't be scared, once you understand trig, it can be your best friend).

These are the formula's you need:
X=R*cos(theta)+Xc
Y=R*sin(theta)+Yc

Where X is the X coordinate of the end of the line, Y is the Y coordinate of the end of the line, R is the distance to go, theta is the angle, and Xc and Yc are the X and Y coordinates of the center of the circle.

You can the just draw a line:

Line Xc,Yc,X,Y

So the only thing you would have to worry about is finding the correct angle (which really isn't that bad, just some division).

Hope this helps!

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
steve paul thomas
16
Years of Service
User Offline
Joined: 4th Nov 2008
Location: United Kingdom
Posted: 25th Nov 2008 21:18
Hi,
Just to get you started, here's some code I used for a DBC Challenge. Credit goes to NanoGamez guy for help with the angle calculation - but the rest of the code I did myself.

Others might have done this a little differently, but this works.

Anyway, paste this into DBC and see if you can learn from it


Login to post a reply

Server time is: 2025-06-07 17:15:46
Your offset time is: 2025-06-07 17:15:46