I'm working on programming an analog clock. As I am ta school, I don't have the code right now. I will load it later.
To re-post my logic from HCWP last night:

- All three hands will sweep through 2pi radians or 360 degrees.
- All three hands will be at pi/2 radians or 90 degrees corresponding to zero minutes, hours, or seconds.
- All three hands sweep clockwise, or towards smaller angles.

For seconds and minutes, 2pi radians covers 60 units (seconds or minutes), so each second or minute is 2pi/60 = pi/30 of the clock face. If the current second is S, then you need to go Spi/30 radians backwards from pi/2 (the starting point), so the angle for any second is .5pi-Spi/30. For minutes, same deal, .5pi-Mpi/30. For hours, you have 12 instead of 60 units, so each unit is 2pi/12 = pi/6 radians, and the angle for any hour is .6pi-Hpi/6. This gives us:

angle_S = .5pi-Spi/30
angle_M = .5pi-Mpi/30
angle_H = .5pi-Hpi/6

Exercise for you: the angle_H is not precisely correct, or is it? What about the fact that the first hour is 12, not 0? Will this still work, or no? If you aren't sure, do the math for angle_H with H=12 and H=0 and see what happens.

Now, how do you draw those? Assuming you have a center at (0,0), you need an (X,Y) point for the end of each hand. For seconds, assuming R is the radius of the seconds hand, it would be:

X = Rcos(.5pi-Spi/30)
Y = Rsin(.5pi-Spi/30)

Same thing for minutes and hours.
Nice! I tried making my own analog clock in Basic once. I got the radial movement down, but I couldn't find a way to erase/refresh the screen without making it look horrible. D:
But best of luck to you! (and be sure to post a screenie/download Smile)
parserp wrote:
Nice! I tried making my own analog clock in Basic once. I got the radial movement down, but I couldn't find a way to erase/refresh the screen without making it look horrible. D:
But best of luck to you! (and be sure to post a screenie/download Smile)
If you do all the Line(x,y,x,y,0)s before drawing the new hands, it doesn't look too bad. Or to avoid flashing as much as possible:

- Erase second hand
- Erase minute hand if seconds=0
- Erase hour hand if minutes=0
- Draw all three hands

That will avoid partially-erased hands, and will also not flicker.
I coded the second hand, but it just is stuck pointing through the second quadrant. I will upload a picture later.
pcb_master wrote:
I coded the second hand, but it just is stuck pointing through the second quadrant. I will upload a picture later.
Did you follow my equations, or more importantly, do you understand how I derived my equations?
I followed your equations exactly, but something is wrong with my code. If I can get TI connect X to work I will load it later.
pcb_master wrote:
I followed your equations exactly, but something is wrong with my code. If I can get TI connect X to work I will load it later.
I could always have made a mistake, as well. It's more important to me that you understand where I got the equations that I wrote than that you copy it exactly. I know you haven't taken trig before, but that use of sine and cosine to get coordinate pairs on the perimeter of a unit circle is fairly straightforward, and I would e happy to explain it more.
Are you sure that your viewing window is X = [-R,R] (And then ZSquare to make circles look right)? Also, if you're using the variables X and Y, then you might be getting a few of them overwritten. Instead use S and T (The letters above X and Y on the keypad). Your code should look something like:
Code:
A = Seconds
B = Minutes
C = Hours
R = Radius
<pi> = The Pi symbol
D = a temporary variable

Code:
Prompt A,B,C
30->R
-R->Xmin
R->Xmax
ZSquare

.5<pi>-A<pi>/30->D
Line(0,0,RCos(D),RSin(D
.5<pi>-B<pi>/30->D
Line(0,0,RCos(D),RSin(D
.5<pi>-C<pi>/6->D
Line(0,0,RCos(D),RSin(D

Circle(0,0,R
That can be optimized quite a bit, but it gives the general idea (Ans should be used instead of D, making a constant out of <pi>/30 might also save a couple bytes).
Oh yes, he said that he was setting his window to have pixel-point matching coordinates, as I recall. In other words, Xmin=Ymax=0, Xmax=94, Ymin=-62. I might recommend using a different radius for each hand, and have the largest radius be smaller than the clock radius. Then you can set two of the window variables and use ZSquare to get nice circular circles.
BASIC Code wrote:
:SetUpEditor ∟TIME
:StoreGDB 1
:0→Xmin
:94→Xmax
:1→XScl
:0→Ymin
:62→Ymax
:1→YScl
:AxesOff
:RecallPic 1
:0→K
:While K≠45
:¦ getTime→∟TIME
:¦ ∟TIME(3)→S
:¦ cos((π/2)-(S*π/30))→X
:¦ sin((π/2)-(S*π/30))→Y
:¦ Line(47,31,X,(62-Y)
:¦ getKey→K
:End
:RecallGDB 1
:Disp
Generated by SourceCoder, © 2005-2012 Cemetech


Here is the non-working code
Did you read above where we discussed why you're getting the quadrant issue? I see that the symptoms are almost exactly what I described, and also that you're using a radius of 1, which won't give you what you want. You can also omit the multiplication signs between the S and pi, change (pi/2) to .5pi (note the removed parentheses) to optimize things a bit.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement