This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
Deo Favente


Newbie


Joined: 17 Sep 2008
Posts: 10

Posted: 24 Nov 2008 12:56:12 pm    Post subject:

I made a calendar program in ti-basic wilhe watching a movie in history (yawn) so i thought i might share it with everyone. For a picture see the attachment, it shows what it would look like on december 22nd [attachment=2531:attachment]. If anyone has any ideas feel free to share them, especially if it makes the code smaller and faster.

Controls:
DEL: exits the program - you must press del! dont break!
ARROWS: move up,down,left,and right. moving left and right at the edge will scroll to the previous or next month.

Bugs:
Feburary always has 28 days, but on the 29th it will highlight the day after the 28th
Program modifies month and year as storage - should change to using a list variable

Upcoming features:
+ and - keys move up and down days, scrolls months if you reach the 1st or the last day of the month
New christmas graphic - please sugesst a picture (12x6 pixels)

Program CALENDAR 11/21/08

Code:
0->Q
getDate->L2

Lbl 0
FnOff
Full
GridOff
AxesOff
0->Xmin
94->Xmax
0->Ymin
62->Ymax
ClrDraw

For(A,0,8)
   Vertical ((A*13)+2)
End

Vertical 0
Vertical 1
Vertical 94

For(X,15,92,13)
   For (Y,1,7)
 Â Pxl-Off(Y,X)
   End
End

getDate->L1
Text(1,77,L1(1))

If L1(2)=1
Then
   Text(1,4,"Janurary")
   30->Z
End
If L1(2)=2
Then
   Text(1,4,"February")
   28->Z
End
If L1(2)=3
Then
   Text(1,4,"March")
   31->Z
End
If L1(2)=4
Then
   Text(1,4,"April")
   30->Z
End
If L1(2)=5
Then
   Text(1,4,"May")
   31->Z
End
If L1(2)=6
Then
   Text(1,4,"June")
   30->Z
End
If L1(2)=7
Then
   Text(1,4,"July")
   31->Z
End
If L1(2)=8
Then
   Text(1,4,"August")
   31->Z
End
If L1(2)=9
Then
   Text(1,4,"September")
   30->Z
End
If L1(2)=10
Then
   Text(1,4,"October")
   31->Z
End
If L1(2)=9
Then
   Text(1,4,"November")
   30->Z
End
If L1(2)=9
Then
   Text(1,4,"December")
   31->Z
End

Text(8,7,"S")
Text(8,20,"M")
Text(8,33,"T")
Text(8,46,"W")
Text(8,59,"T")
Text(8,72,"F")
Text(8,85,"S")

L1(1)->Y
L1(2)->M
1->D
2->R
prgmDAYOWEEK
2+D->D
If d>7
D-7->D
For(A,1,Z)
   If int(log(a))=1
   Then
 Â If (M=/=12) or ((M=12) and (A=/=25))
 Â Text(R*7+1,(D-1)*13+5,A)
   End
   If (M=12) and (A=25)
   Then
 Â R*7+1->X
 Â (D-1)*13+5->Y
 Â 
 Â Pxl-On(X,Y+3)
 Â Pxl-On(X+1,Y+2)
 Â Pxl-On(X+1,Y+4)
 Â Pxl-On(X+2,Y+1)
 Â Pxl-On(X+2,Y+5)
 Â For(K,0,6)
 Â    Pxl-On(X+4,Y+3)
 Â End
 Â Pxl-On(X+4,Y+3)
 Â Pxl-On(X+5,Y+3)

   End
   If int(log(A))=0
   Text(R*7+1,(D-1)*13+7,A)
   
   If A=L1(3)
   Then
 Â If Q=0
 Â {D,R}->LC
   End
   
   D+1->D
   If D=8
   Then
 Â 1->D
 Â 1+R->R
   End
End

prgmCOLORCEL

For(A,1,9)
   Horizontal ((A*7)-1)
end

For(X,2,94,13)
   For (Y,57,62)
 Â Pxl-Off(Y,X)
   End
End

{0,1,2,94}->L6
For(X,1,4)
   For(Y,57,62)
 Â Pxl-Off(Y,L6(x))
   End
End

Lbl 1
Repeat Ans
   getKey
End

If Ans=24
Then
   
   If LC(1)=/=1
   Then
 Â prgmCOLORCEL
 Â {LC(1)-1,LC(2)}->LC
 Â prgmCOLORCEL
   
   Else
 Â If LC(1)=1
 Â Then
 Â    
 Â    1->Q
 Â    {7,LC(2)}->LC
 Â    getDate->L1
 Â    If L1(2)=/=1
 Â    Then
 Â   setDate(L1(1),L1(2)-1,L1(3))
 Â    Else
 Â   setDate(L1(1)-1,12,L1(3))
 Â    End
 Â    Goto 0
 Â End
   End
   
Else
   If Ans=25
   Then
 Â 
 Â If LC(2)>1
 Â Then
 Â    prgmCOLORCEL
 Â    {LC(1),LC(2)-1}->LC
 Â    prgmCOLORCEL
 Â End
   Else
 Â If Ans=26
 Â Then
 Â    If LC(1)=/=7
 Â    Then
 Â   
 Â   prgmCOLORCEL
 Â   {LC(1)+1,LC(2)}->LC
 Â   prgmCOLORCEL
 Â    
 Â    Else
 Â   If LC(1)=7
 Â   Then
 Â      
 Â      1->Q
 Â      {1,LC(2)}->LC
 Â      getDate->L1
 Â      If L1(2)<12
 Â      Then
 Â     setDate(L1(1),L1(2)+1,L1(3))
 Â      Else
 Â     setDate(L1(1)+1,1,L1(3))
 Â      End
 Â      Goto 0
 Â      
 Â   End
 Â    End
 Â Else
 Â    If Ans=34
 Â    Then
 Â   
 Â   If LC(2)<7
 Â   Then
 Â      prgmCOLORCEL
 Â      {LC(1),LC(2)+1}->LC
 Â      prgmCOLORCEL
 Â   End
 Â    Else
 Â   If Ans=23
 Â   Then
 Â      
 Â      setDate(L2(1),L2(2),L2(3))
 Â      Return
 Â      
 Â   Else
 Â      
 Â   End
 Â    End
 Â End
   End
End

Goto 1


Program COLORCEL 11/20/08

Code:
If LC(2)=/=1
Then
   For(X,((LC(1)-1)*13)+3,((LC(1)-1)*13)+14)
 Â For(Y,(LC(2)*7)+1,(LC(2)*7)+6)
 Â    Pxl-Change(Y,X)
 Â End
   End
End
Return


Program DAYOWEEK 11/20/08

Code:
If M<3
Then
   M+12->M
   Y-1->Y
End

(D+(2*M)+int(6*(M+1)/10))+Y+int((Y/4))-int((Y/100))+int((Y/400))->D
D-(7*int(D/7))->D


Last edited by Guest on 24 Nov 2008 01:07:28 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 25 Nov 2008 12:29:17 am    Post subject:

I know you didn't transcribe all those parts correctly – I think there are 31 days in January, and November and December are not exactly the ninth month. If you have the .8xp file handy, you can open it with SourceCoder to make life easier. But as a second note, [escape][code][/escape] is the tag to use if your program stretches a good long distance (and it does).

Anyway, you're just learning to use the language effectively and you want to show off something you made. I completely understand that, but there are a ton of commands that await your exploration, and your... restricted use of what concepts are available to you suggests that you need to engage yourself in more experimentation overall, even with the known commands. For example, Line( can be used to turn off pixels. Did you know that? (Try adding an optional ,0 to the end of the four usual arguments.)

For() is a powerful command. sub() (found in the CATALOG) is powerful, too. Whenever you have a range of information that you want to display in a linear fashion, For() should immediately come to mind. If that involves text, then sub() suddenly becomes your new best friend:

For(A,1,7
Text(8,13A-6,sub("SMTWTFS",A,1
End

Likewise, let's release the fury of sub() on your If L1(2)=N blocks:

Text(1,4,sub("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",3L1(2)-2,3
{31,28,31,30,31,30,31,31,30,31,30,31
Ans(L1(2→Z

That whole section of your program just went from "bump-ba-bump-ba-bump" to something much more streamlined...

Now, instead of:

2+D→D
If D>7
D-7→D

Check this out:

2+D→D
D-7(D>7→D

Now, see what happens if we substitute the second line's D with the expression stored to D in the line before it:

(2+D)-7((2+D)>7→D

Simplify:

D+2-7(D>5→D

Three lines are now compressed into one line. The reason this works is because the calculator takes comparisons (such as = and [font="verdana"]≥
) and evaluates them to 1 or 0 (one being "true" and zero being "false"). In the line above, the result gets multiplied by seven, ...yada yada. You'll find that these piecewise expressions are frequently used as an optimization tool in TI-Basic.

Now, parentheses used with the intention of separating logical operators (and, or, xor, etc.) are rarely necessary, since the interpreter binds them together tightly – that is, if we look at the order of operations, the expressions get evaluated first, and then are compared to one another with these operators.

If (M≠12) or ((M=12) and (A≠25))

...is equivalent to...

If M≠12 or M=12 and A≠25.

It's important to note that or is given lower priority than and, thus allowing for the safe drop of the outside set of parentheses.

Just an interesting thing I noticed in your first If-Then-Else block:

If LC(1)≠1
Then

Else
If LC(1)=1

End

If you do the one test, isn't the other test automatically the Else? So the latter can be omitted, leaving you with...

If LC(1)≠1
Then

Else

End

It's less explicit, but logically equivalent. You can do the same thing with the If LC(1)≠7 further down. Also, rearranging the condition to drop a parenthesis—If 1=LC(1)—allows that extra byte to go towards another program. Do this 99 more times, and you'll have an extra 100 bytes to work with.

Looking at this block:

If L1(2)≠1
Then
setDate(L1(1),L1(2)-1,L1(3))
Else
setDate(L1(1)-1,12,L1(3))
End

Taking what we've learned regarding piecewise expressions, and applying the Ans variable directly, we can completely exchange this code block with the following:

1≠L1(2
setDate(L1(1)-not(Ans),12+Ans(L1(2)-13),L1(3

That's a good chunk of bytes saved! You can do the same thing (roughly) with the If L1(2)<12 case:

12>L1(2
setDate(L1(1)+not(Ans),1+AnsL1(2),L1(3

I'm going to show you what prgmCOLORCEL looks like when fully optimized:

If 1≠LC(2
Then
1+13LC(1
For(X,Ans-11,Ans
1+7LC(2
For(Y,Ans,Ans+5
Pxl-Change(Y,X
End
End
End

Note the abundant lack of parentheses.

Now, I will go down to this last line in prgmDAYOWEEK:

(D+(2*M)+int(6*(M+1)/10))+Y+int((Y/4))-int((Y/100))+int((Y/400))→D

If ever you can't decide on whether using parentheses would be appropriate, then run a few tests on the home screen to come up with an answer. The negative effect of a line being completely riddled with punctuation is that it becomes difficult to see other ways to improve it.

This line is in every way equal to that above:

D+2M+Y+int(.6M+.6+sum(iPart(Y/{400,-100,4

(Are you aware that there is a dayOfWk() function on your calculator?)

Much of what I said can be reapplied to different sections in your program (or in any program, for that matter), and I left a good number of stones unturned and things unsaid. However, whether you want to attempt a few experiments here and there so as to try to figure out new stuff is (always) up to you.

Keep exploring! Smile

Last edited by Guest on 22 Jul 2010 11:40:50 am; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 25 Nov 2008 10:39:25 am    Post subject:

Weregoose wrote:
(Are you aware that there is a dayOfWk() function on your calculator?)
[post="129452"]<{POST_SNAPBACK}>[/post]

I thought that was 84+ only... am I mistaken?


Last edited by Guest on 22 Jul 2010 11:31:35 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 25 Nov 2008 11:41:33 am    Post subject:

There is, however, a very short routine that can simulate the effect of dayOfWk( on a TI-83, TI-83+, or TI-83+ SE, using dbd(.

Last edited by Guest on 25 Nov 2008 11:41:50 am; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 25 Nov 2008 11:47:32 am    Post subject:

Also, you use getDate at the start of your program, which is also 84+ only. If you use one, you may as well use the other.
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 25 Nov 2008 05:38:11 pm    Post subject:

I think your response justifies use of a [[color=#222]c[/color]odebox], Goose, geez. And thanks for the tip on how to make BBCode tags appears as is, instead of parsing them Smile.

I would suggest a good look into TI|BD, it's a huge repository with all the essentials as well as all the little frills of Basic.
Back to top
Flameviper


Advanced Newbie


Joined: 05 Jun 2008
Posts: 62

Posted: 28 Nov 2008 07:37:18 pm    Post subject:

A way to really crunch the file size would be to use string functions. They're not used often, they're a bit scary at first, and they're always scary, but they're useful.

Like instead of that whole "If L1(2)=X:Then:Output(foo,bar,"bazuary":end" abomination, you could do this instead.


Code:
"JANUARY____FEBRUARY__MARCH_____APRIL_____MAY_______JUNE______JULY______AUGUS
T____SEPTEMBER_OCTOBER___NOVEMBER__DECEMBER__"->Str1
Output(foo,bar,Sub(Str1,(10*L1(2))-9,10)


And yes, that last line is an absolute bitch.

I can explain it if you'd like, or you can just cargo-cult it Razz


Last edited by Guest on 28 Nov 2008 07:39:48 pm; edited 1 time in total
Back to top
Deo Favente


Newbie


Joined: 17 Sep 2008
Posts: 10

Posted: 10 Dec 2008 12:36:09 pm    Post subject:

@Weregoose:
1)yes, suggestions like those are exactly what im looking for. Thank you. I'll add these suggestions to my program when i get a chance
2)I'm new to TI-BASIC but i have experience in OOP languages.
3)No, i dont have the file handy cause TiLP always crashed whenever i try to get a file from my calculator. I'm still trying to get it to work.
4) About janurary, on my calc it does hav 31->Z i just copeied it down wrong.
5)I had no idea that functions like sub and dayofweek exsisted on my calculator, havent explored much yet. I also have little idea what the arguments are, again havent had much time to look online for the reference.
6)I dont like to shorten programs byleaving off the last ) or } - makes it harder to read, but ill implement the other optimizations.
7) I'm aware of the
Quote:
Now, instead of:

2+D→D
If D>7
D-7→D

Check this out:

2+D→D
D-7(D>7→D

Now, see what happens if we substitute the second line's D with the expression stored to D in the line before it:

(2+D)-7((2+D)>7→D

Simplify:

D+2-7(D>5→D

Three lines are now compressed into one line. The reason this works is because the calculator takes comparisons (such as = and ≥) and evaluates them to 1 or 0 (one being "true" and zero being "false"). In the line above, the result gets multiplied by seven, ...yada yada. You'll find that these piecewise expressions are frequently used as an optimization tool in TI-Basic.

i guess i just wasnt awake while i was writing that part of the porgram silly me.
Cool I'm aware of this too, it just makes it easier for me to debug the program
Quote:
Now, parentheses used with the intention of separating logical operators (and, or, xor, etc.) are rarely necessary, since the interpreter binds them together tightly � that is, if we look at the order of operations, the expressions get evaluated first, and then are compared to one another with these operators.

If (M≠12) or ((M=12) and (A≠25))

...is equivalent to...

If M≠12 or M=12 and A≠25.

9)
Quote:
Just an interesting thing I noticed in your first If-Then-Else block:

If LC(1)≠1
Then
�
Else
If LC(1)=1
�
End

If you do the one test, isn't the other test automatically the Else? So the latter can be omitted, leaving you with...

If LC(1)≠1
Then
�
Else
�
End

Yea i must have really been sleeping
10) This optimization is quite helpful thank you

Code:
D+2M+Y+int(.6M+.6+sum(iPart(Y/{400,-100,4

This was my problem:
Quote:
The negative effect of a line being completely riddled with punctuation is that it becomes difficult to see other ways to improve it.

Again thanks for all the suggestions, this is the reason i made this thread.

@Flameviper:
Yes, i was looking for something like that
Back to top
Deo Favente


Newbie


Joined: 17 Sep 2008
Posts: 10

Posted: 10 Dec 2008 01:09:44 pm    Post subject:

So i shorted that first huge section to four lines and changed to the smtwtfs thing:

Code:
{31,28,31,30,31,30,31,31,30,31,30,31}->LB
LB(L2(2))->Z
"Janurary_Feburary_March____April____May______June_____July_____August___Sept
emberOctober__November_December_"->Str1
Text(1,4,Sub(Str1,(9*L1(2))-9,9)
For(A,1,7)
Text(8,13A-6,sub("SMTWTFS",A,1)
End

That optimization made my program go from the size of it is today, after two new features, to the size of the program i posted. sweet.

I'm at school right now so i cant make all the changes


Last edited by Guest on 10 Dec 2008 01:20:18 pm; edited 1 time in total
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement