I made a clock program in ti basic for the TI-84 and other TI-BASIC calculators.

Code:

"Setup Code"
ClrDraw
ClrHome
AxesOff
1.3->Xmax
1.3->Ymax
-1.3->Xmin
-1.3->Ymin
ZSquare
Radian
Circle(0,0,1

"Tick Drawing"
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

"Hand Drawing"
Lbl A
  "Split Time List Var Into 2 INT Vars"
  getTime->L1
  L1[1]->H
  L1[2]->M
 
  "Draw Hour Hand"
  Line 0,0,.5*sin((H-1)*pi/6),.5*cos((H-1)*pi/6),0
  Line 0,0,.5*sin((H-1)*pi/6),.5*cos((H*pi/6),1
 
  "Draw Minute Hand"
  Line 0,0,.7*sin((M-1)*pi/30),.7*cos((M-1)*pi/6),0
  Line 0,0,.7*sin((M-1)*pi/30),.7*cos((M*pi/30),1
Goto A


Can I get some feedback on this code? Good Idea Also, I changed my email on my old acct @izder456 bc i acquired a new email address and I got banned Surprised . Can I get this account recovered Idea ? I didn't know that was a rule Wink .
Does that code even work for you? It doesn't work for me. Here are some things that immediately stand out to me and some code fixes.
1. You used the minus sign (-) rather than the negative sign (~) on the 7 and 8th line.
2. You used double quote comments (") rather than the double backslash (//) comments. // comments don't get put in your program when you compile it from SC and therefor don't slow down your program like " comments do.
3. Perhaps you should add that this will only work on the monochrome TI 84s since it didn't work on my CE. add the command that turns off the y= functions since I thought this program wasn't working, only to realize a while later that my calculator was just graphing something outside of the window range.
3.5. Utilize the Graph DataBase (GDB) function so you can reset the users window and other data back to what it was before they ran the program. It's a nice touch that makes users really appreciate the programmer.
4. On lines 28 and 29 you used brackets when you need to use parenthesis.
5. Line 32,33,36,37 you put a space after the Line( command rather than an open parenthesis
6. line 33,37 there should not be a 1 as the last argument.
7. I don't understand what the code under "tick drawing" is suppose to do, it distorts the clock face for me.
8. You used a Lbl/Goto loop rather than a While or Repeat loop. I highly suggest not using the Lbl loop since it creates a infinite loop you can't get out of unless you press [on] which is not a very clean exit option.
While loops allow you to loop until a condition is not met.
Repeat loops allow you to loop until a condition is met. I suggest using either one of these loops and utilizing the getKey command to detect when the user wants to quit the program.

Here's the final, working code I ended up with.

Code:
//Stores the current window to GDB 1 to be recalled later
StoreGDB 1
//sets up a friendly window
ClrDraw
AxesOff
FnOff
1.3->Xmax
1.3->Ymax
~1.3->Xmin
~1.3->Ymin
ZSquare
//changes mode to Radians
Radian
//draws the clock face
Circle(0,0,1

//Draws the clock hands
//THis loops until the user presses any key.
Repeat getKey
  //Split Time List Var Into 2 INT Vars
  getTime->L1
  L1(1)->H
  L1(2)->M
 
  //Draw Hour Hand
  Line(0,0,.5*sin((H-1)*pi/6),.5*cos((H-1)*pi/6),0
  Line(0,0,.5*sin((H-1)*pi/6),.5*cos((H*pi/6)
 
  //Draw Minute Hand
  Line(0,0,.7*sin((M-1)*pi/30),.7*cos((M-1)*pi/6),0
  Line(0,0,.7*sin((M-1)*pi/30),.7*cos((M*pi/30
End
//Resets the graph back to its original state
FnOn
RecallGDB 1


EDIT:
Quote:
Can I get some feedback on this code? Good Idea Also, I changed my email on my old acct @izder456 bc i acquired a new email address and I got banned Surprised . Can I get this account recovered Idea ? I didn't know that was a rule Wink .
Changing your email isn't against the rules. You'll want to PM KermMartian, Tari, or PT_ about account recovery.
sorry I originally wrote it on a voyage 200 and I accidentally used a mix of the syntax of 68k and ti-basic
TheLastMillennial wrote:
Does that code even work for you? It doesn't work for me. Here are some things that immediately stand out to me and some code fixes.
1. You used the minus sign (-) rather than the negative sign (~) on the 7 and 8th line.
2. You used double quote comments (") rather than the double backslash (//) comments. // comments don't get put in your program when you compile it from SC and therefor don't slow down your program like " comments do.
3. Perhaps you should add that this will only work on the monochrome TI 84s since it didn't work on my CE. add the command that turns off the y= functions since I thought this program wasn't working, only to realize a while later that my calculator was just graphing something outside of the window range.
3.5. Utilize the Graph DataBase (GDB) function so you can reset the users window and other data back to what it was before they ran the program. It's a nice touch that makes users really appreciate the programmer.
4. On lines 28 and 29 you used brackets when you need to use parenthesis.
5. Line 32,33,36,37 you put a space after the Line( command rather than an open parenthesis
6. line 33,37 there should not be a 1 as the last argument.
7. I don't understand what the code under "tick drawing" is suppose to do, it distorts the clock face for me.
8. You used a Lbl/Goto loop rather than a While or Repeat loop. I highly suggest not using the Lbl loop since it creates a infinite loop you can't get out of unless you press [on] which is not a very clean exit option.
While loops allow you to loop until a condition is not met.
Repeat loops allow you to loop until a condition is met. I suggest using either one of these loops and utilizing the getKey command to detect when the user wants to quit the program.

Here's the final, working code I ended up with.

Code:
//Stores the current window to GDB 1 to be recalled later
StoreGDB 1
//sets up a friendly window
ClrDraw
AxesOff
FnOff
1.3->Xmax
1.3->Ymax
~1.3->Xmin
~1.3->Ymin
ZSquare
//changes mode to Radians
Radian
//draws the clock face
Circle(0,0,1

//Draws the clock hands
//THis loops until the user presses any key.
Repeat getKey
  //Split Time List Var Into 2 INT Vars
  getTime->L1
  L1(1)->H
  L1(2)->M
 
  //Draw Hour Hand
  Line(0,0,.5*sin((H-1)*pi/6),.5*cos((H-1)*pi/6),0
  Line(0,0,.5*sin((H-1)*pi/6),.5*cos((H*pi/6)
 
  //Draw Minute Hand
  Line(0,0,.7*sin((M-1)*pi/30),.7*cos((M-1)*pi/6),0
  Line(0,0,.7*sin((M-1)*pi/30),.7*cos((M*pi/30
End
//Resets the graph back to its original state
FnOn
RecallGDB 1


Here is the original code for 68k Calculators modified with your suggestions. it doesn't look like 68k uses the repeat loop:


Code:

//Stores the current window to GDB 1 to be recalled later
StoGDB 1
//sets up a friendly window
ClrDraw
setGraph("axes","off")
FnOff
1.3->Xmax
1.3->Ymax
~1.3->Xmin
~1.3->Ymin
ZoomSqr
//changes mode to Radians
setMode("Angle","RADIAN")
//draws the clock face
Circle 0,0,1

//Draws the clock hands
//This loops until the user presses any key.
while getKey!=1
  //Split Time List Var Into 2 INT Vars
  getTime()->L1
  L1[1]->H
  L1[2]->M
 
  //Draw Hour Hand
  Line 0,0,.5*sin((H-1)*pi/6),.5*cos((H-1)*pi/6),0
  Line 0,0,.5*sin((H-1)*pi/6),.5*cos((H*pi/6)
 
  //Draw Minute Hand
  Line 0,0,.7*sin((M-1)*pi/30),.7*cos((M-1)*pi/6),0
  Line 0,0,.7*sin((M-1)*pi/30),.7*cos((M*pi/30
EndWhile
//Resets the graph back to its original state
FnOn
RclGDB 1
sorry, I made a temp account as I got locked out of the izder456 account for changing my email. redsn0w was said account.

anyways, here's the updated code with numbers on the 0,90,180,270 degrees of the circle:


Code:

clock()
Prgm

“Setup Code”
StoGDB a
ClrDraw
ClrIO
ClrHome
FnOff
setGraph(“axes”,”off”)

“Set Window”
1.3->xmax
1.3->ymax
⁻1.3->xmin
⁻1.3->ymin
ZoomSqr
setMode(“Angle”,”RADIAN”)

“Draw Clock Base”
Circle 0,0,1
PtText “12”,⁻.15,1.2
PtText “6”,⁻.08,⁻1.05
PtText “9”,⁻1.2,.08
PtText “3”,1.05,.08

“Draw 3 hour,5 minute, and 1 minute tick marks”
For b,0,60*π/30,π/30
 Line .925*cos(b),.925*sin(b),cos(b),sin(b)
EndFor
For b,0,12*π/6,π/6
 Line .85*cos(b),.85*sin(b),cos(b),sin(b)
EndFor
For b,0,4*π/2,π/2
 Line .8*cos(b),.8*sin(b),cos(b),sin(b)
EndFor

"repeats until a key is pressed"
While getKey()=0
 "split time List var into two INT vars"
 getTime()->l1
 l1[1]->h
 l1[2]->m
 "draw hands"
 Line 0,0,.5*sin((h-1)*π/6),.5*cos((h-1)*π/6),0
 Line 0,0,.5*sin(h*π/6),.5*cos(h*π/6),1
 Line 0,0,.7*sin((h-1)*π/30),.7*cos((h-1)*π/30),0
 Line 0,0,.7*sin(h*π/30),.7*cos(h*π/30),1
EndWhile
FnOn
RclGDB a
EndPrgm


edit: this code is for 68k calculators
New Topic Here: https://www.cemetech.net/forum/viewtopic.php?p=277342#277342
Fixed source:

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


note: the "draw ticks" lines of code draw 3 hour, 5 minute, and 1 minute tick marks on the clock face.

note (part 2): you can convert the code to color calculators by changing arguments of the Text( function by changing the 0 to white in the line functions
  
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