Don't have an account? Register now to chat, post, use our tools, and much more.
This is an analog clock program using the unit circle.
the weird decimal places in the Repeat loop are to fix a ghosting bug when drawing hands

Code:
``` //setup StoreGDB 1 FnOff AxesOff ClrDraw //set friendly window 1.3->Xmax 1.3->Ymax ~1.3->Xmin ~1.3->Ymin ZSquare Radian //draw clock face Circle(0,0,1 //draw tick marks For(B,0,60*pi/30,pi/30  Line(.925*cos(B),.925*sin(B),cos(B),sin(B) End For(B,0,12*pi/6,pi/6  Line(.85*cos(B),.85*sin(B),cos(B),sin(B) End For(B,0,4*pi/2,pi/2  Line(.8*cos(B),.8*sin(B),cos(B),sin(B) End //draw hour labels Text(0,44,"12 Text(28,75,"3 Text(56,46,"6 Text(28,19,"9 //repeats until keypress Repeat getKey  //erase previously drawn hour hand and the draw a new one  getTime->L1  L1(1)->H  Line(0,0,.45*sin((H-1)*pi/6),.5*cos((H-1)*pi/6),0  Line(0,0,.45*sin((H)*pi/6),.5*cos((H)*pi/6)  //erase previously drawn minute hand and the draw a new one  getTime->L1  L1(2)->M  Line(0,0,.65*sin((M-1)*pi/30),.7*cos((M-1)*pi/30),0  Line(0,0,.65*sin((M)*pi/30),.7*cos((M)*pi/30)  //erase previously drawn second hand and the draw a new one  getTime->L1  L1(3)->S  Line(0,0,.7*sin((S-1)*pi/30),.75*cos((S-1)*pi/30),0  Line(0,0,.7*sin((S)*pi/30),.75*cos((S)*pi/30)          //draw date in corners of screen  getDate->L2  Text(55,74,L2(1)  Text(1,1,L2(2)  Text(7,1,L2(3) End RecallGDB 1 ```

an explanation with full source would be very nice (maybe in "//" comments?)
As I found out when I challenged everyone to some code golfing, I am not as good at optimizing as some other people, but I'll do my best to help in this particular case.
Also, This seems to be for a monochrome, I only have a TI-84 Plus CE, so forgive me if I do something impossible on mono calcs.
Code:
```//setup StoreGDB 1 FnOff AxesOff ClrDraw //set friendly window 1.3->Ymax // ZSquare only takes the Y axis into account iirc ~Ans->Ymin // Ans saves 2 bytes ZSquare Radian //draw clock face Circle(0,0,1 //draw tick marks For(B,0,2pi,pi/30 // each fraction simplifies to 2pi    B/pi // yes, more ans work :P    .925-.075(6Ans=iPart(6Ans))-.05(2Ans=iPart(2Ans // This long line sets the size of the tick mark so you don't have to do it in separate loops    // I was going to use some sine trickery here, but it was too inconsistent.    Line(Anscos(B),Anssin(B),cos(B),sin(B // you don't need these closing parentheses End // This saved quite a bit of space :) //draw hour labels Text(0,44,12 // It'll display numbers just like strings. Text(28,75,3 Text(56,46,6 Text(28,19,9 //repeats until keypress Repeat getKey    // Update hands    getTime->T // Why are you getTiming every time a hand updates? One GetTime works for all of them.    For(A,1,0,~1 // I hope this works for you because I have no idea what gave me the idea that this would work :P       |LT(1       Line(0,0,.45sin((Ans-A)pi/6),.5cos((Ans-A)pi/6),not(A       |LT(2       Line(0,0,.65sin((Ans-A)pi/30),.7cos((Ans-A)pi/30),not(A       |LT(3       Line(0,0,.7sin((Ans-A)pi/30),.75cos((Ans-A)pi/30),not(A    End    //draw date in corners of screen    getDate // No reason to use any list    Text(55,74,Ans(1    Text(1,1,Ans(2    Text(7,1,Ans(3 End RecallGDB 1```
(hey, 535->323 bytes isn't bad, right?)

Here are 2 alternate hand drawers:

Code:
```getTime->L1 Ans(1->N // using Ans saves 1 byte Line(0,0,.45sin((N-1)pi/6),.5cos((N-1)pi/6),0 //the * doesn't need to be between the function and the number Line(0,0,.45sin(Npi/6),.5cos(Npi/6 // Lone variables don't need to be in parentheses L1(2->N Line(0,0,.65sin((N-1)pi/30),.7cos((N-1)pi/30),0 Line(0,0,.65sin(Npi/30),.7cos(Npi/30 L1(3->N Line(0,0,.7sin((N-1)pi/30),.75cos((N-1)pi/30),0 Line(0,0,.7sin(Npi/30),.75cos(Npi/30 ```
OR:
Code:
```  //erase previously drawn hour hand and the draw a new one         getTime->T // Why are you getTiming every time a hand updates? One GetTime works for all of them.         Ans(1 // Ans saves 1 byte         For(A,1,0,~1 // I hope this works for you :P           Line(0,0,.45sin((Ans-A)pi/6),.5cos((Ans-A)pi/6),not(A         End    //erase previously drawn minute hand and the draw a new one         |LT(2         For(A,1,0,~1           Line(0,0,.65sin((Ans-A)pi/30),.7cos((Ans-A)pi/30),not(A         End    //erase previously drawn second hand and the draw a new one         |LT(3         For(A,1,0,~1 // I'm sure there is a way to combine all of these into a single loop :/           Line(0,0,.7sin((Ans-A)pi/30),.75cos((Ans-A)pi/30),not(A         End```

I wanted to use the Sequential Graphing functions, but I don't know if the are available on mono calcs :/

Hope this helps!
LogicalJoe wrote:

I wanted to use the Sequential Graphing functions, but I don't know if the are available on mono calcs :/

yes you can. it's the seq( function
your code using the for loop for the hands works. a little buggy.

how were you going to use the seq function anyways

also when c+p into sourcecoder 3 the ZSquare didn't like only the Ymax and Ymin defined, so I had to change the code to:

Code:
``` //set friendly window 1.3->Ymax ~Ans->Ymin // Ans saves 2 bytes 1.3->Xmax ~Ans->Xmin ZSquare Radian```

if you want to port this to ti84ce you can change the fifth argument in Line( to "WHITE" to erase so i don't think the not( will work in that case. also the text coordinates would have to be changed to match the clock's pos

but there's more!

i gettimed every hand draw bc the drawing and erasing would sometimes lag behind a second
Slightly smaller version using one Sequential Graphing Function:
Code:
```//setup StoreGDB 1 FnOff AxesOff ClrDraw //set friendly window 1.3->Ymax Ans->Xmax // Using Ans like this saves quite a bit of extra space ~Ans->Ymin Ans->Xmin ZSquare Radian "(Ans-A)pi->|u // This is a Sequential Graphing Function //draw clock face Circle(0,0,1 //draw tick marks For(B,0,2pi,pi/30     .925-sum({.075,.05}not(fPart(round(B/pi{6,2 // Thank you lirtosiast!     Line(Anscos(B),Anssin(B),cos(B),sin(B End //draw hour labels Text(0,44,12 Text(28,75,3 Text(56,46,6 Text(28,19,9 //repeats until keypress Repeat getKey    // Update hands    getTime->T     For(A,1,0,~1         |LT(1         Line(0,0,.45sin(|u/6),.5cos(|u/6),not(A         |LT(2         Line(0,0,.65sin(|u/30),.7cos(|u/30),not(A         |LT(3       Line(0,0,.7sin(|u/30),.75cos(|u/30),not(A     End     //draw the date in the corners     getDate    Text(55,74,Ans(1    Text(1,1,Ans(2    Text(7,1,Ans(3 End RecallGDB 1```
Forgive the highlighting.

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.

»
» All times are GMT - 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