BackStory:
I was testing out the TI-84+CSE and needed to center some text on the screen at a specific X value. This was a problem because the Text command uses the given X value as the Top Left Most pixel in your String not the Center. I did the math, but it didn't work out since the font in TI-Basic does not have the same width in pixels. To fix the problem, I devised that I would write a simple program to find the exact X value to use in the Text command to have it centered on the X pixel of your choice. I was wrong about one thing, simple.

Explanation:
This text program can be run in two ways: by user or by a program. My original plan was for it to take program calling only, but now you would only use it as a subprogram if a String was updated by the user because of the amount of time it takes to calculate (5-10 secs). The main use for this program is by the user to calculate their X Value they need to center their String in the Text command on their calculator.

How to Use: User
Run program and enter the X Value to Center the Text on. Next use the Calculator's Keyboard to enter your text. It is a custom Input program so don't bother using the Alpha button. As of right now, you can only input .,;: while editing the program because I just did [Space] and all lowercase and uppercase letters. To switch between uppercase, lower case, and numbers, use ↑ and ↓ on the calculator. To backspace, use the ← on the calculator. To space, use the regular space key. Press Enter when you are done.

How to Use: Program
On your program, you will have three inputs: Str1 and two arguments in the list |LTXT. Set Str1 to your Text. Set |LTXT(1) to your X Value to center the Text on. Set |LTXT(2) to 1 to indicate you are a calling it as a subprogram. It will return the needed X Value in |LTXT(3).


PasteBin: http://pastebin.com/Vi7wPXwy

Code:
SetUpEditor |LTXT
6->dim(|LTXT
//Checks if run from Program or User
If |LTXT(2)=0:Then
ClrHome
Disp "Text Centering Tool"
If |LTXT(5)=0:Then
Input "X Pixel to Center On: ",A
Else
Disp "X Pixel to Center On: 132"
132->A
End
//Setup of Variables
A->|LTXT(1)
//Text Input w/ Lowercase and Uppercase Letters
//Setup for Variables
0->B
" "->Str1
0->C
0->D
2->F
5->H
0->I
//Converting the Inputting X Value to a String
{0,1}->L1
{0,|LTXT(1)}->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str2
sub(Str2,1,length(Str2)-3->Str2
DelVar {Y1}
//Outputting Text
Output(3,1,"Text String: "
If |LTXT(6)=0:Then
Output(7,1,"Quit: Period Key"
Output(8,1,"Settings: (-) Key
Output(9,1,"Key Help: Right Arrow"
End
Output(10,1,"Style: Uppercase"
//Main getKey Loop
Repeat A=105
getKey->A
//Quit
If A=103:Then
{0,0,|LTXT(3),|LTXT(4),|LTXT(5),|LTXT(6)}->|LTXT
ClrHome
Stop
End
//Settings
If A=104:Then
For(A,0,1)
If |LTXT(4)=A:sub("No Yes",(1+(3*(A=1))),3)->Str8
If |LTXT(5)=A:sub("No Yes",(1+(3*(A=1))),3)->Str7
If |LTXT(6)=A:sub("Yes No",(1+(3*(A=1))),3)->Str6
End
ClrHome
Disp "SETTINGS","*Show Centered Text: "+Str8," Default X to 132: "+Str7," Tool-Tips: "+Str6," Return to Program"
//Custom Settings Menu
Repeat F=12
getKey->E
If E=34:Then
If F<H:Then
F+1->F
1->I
End
If F=H and I=0:2->F
0->I
End
If E=25:Then
If F>2:Then
F-1->F
1->I
End
If F=2 and I=0:H->F
0->I
End
If E!=G and F!=H and E=26 or E!=G and F!=H and E=24 or E!=G and F!=H and E=105:Then
If F=2:(1-(|LTXT(4)=1)->|LTXT(4
If F=3:(1-(|LTXT(5)=1)->|LTXT(5
If F=4:(1-(|LTXT(6)=1)->|LTXT(6
For(A,0,1)
If |LTXT(4)=A:sub("No Yes",(1+(3*(A=1))),3)->Str8
If |LTXT(5)=A:sub("No Yes",(1+(3*(A=1))),3)->Str7
If |LTXT(6)=A:sub("Yes No",(1+(3*(A=1))),3)->Str6
End
Output(2,22,Str8
Output(3,20,Str7
Output(4,13,Str6
End
If E!=G and E=34 or E!=G and E=25:Then
For(A,2,10
Output(A,1," "
End
Output(F,1,"*"
End
If E!=G and F=H and E=105:12->F
E->G
End
2->F
ClrHome
Disp "Text Centering Tool"
Disp "X Pixel to Center On: "+Str2
End
//Key Help
If A=26:Then
ClrHome
Disp "KEY HELP","Alphabet is Normal","Symbols are 2nd to STAT","Symbols: .,:;!?","Up-Down switch Style","Left Arrow is Backspace","Right Arrow is Help","","Back = Enter Key"
Pause
ClrHome
Disp "Text Centering Tool"
Disp "X Pixel to Center On: "+Str2
End
//Up Style Changer
If A=25:Then
If B>0:Then
B-1->B
1->I
End
If B=0 and I=0:2->B
0->I
End
//Down Style Changer
If A=34:Then
If B<2:Then
B+1->B
1->I
End
If B=2 and I=0:0->B
0->I
End
//Backspace
If A=24:2->C
//Backspace Brain
If length(Str1)>0 and C=2:Then
If length(Str1)=1:Then
" "->Str1
0->C
Else
sub(Str1,1,length(Str1)-1)->Str1
Output(3,1,"Text String: "+Str1+" "
1->C
End:End
//Main Output Update
Output(3,1,"Text String: "+Str1
If |LTXT(6)=0:Then
Output(7,1,"Quit: Period Key"
Output(8,1,"Settings: (-) Key
Output(9,1,"Key Help: Right Arrow"
End
If B=1:Output(10,1,"Style: Lowercase"
If B=0:Output(10,1,"Style: Uppercase"
If B=2:Output(10,1,"Style: Number   "
If A>20 and A<24 or A>30 and A<34 or A>40 and A<44 or A>50 and A<56 or A>60 and A<66 or A>70 and A<76 or A>80 and A<86 or A>90 and A<95 or A=102:Then
If A>20 and A<24:A+7->D
If A>30 and A<34:A->D
If A>40 and A<44:A-40->D
If A>50 and A<56:A-47->D
If A>60 and A<66:A-52->D
If A>70 and A<76:A-57->D
If A>80 and A<86:A-62->D
If A>90 and A<95:A-67->D
If A=102:A-75->D
If B=0:Str1+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ  .,:;!?",D,1)->Str1
If B=1:Str1+sub("abcdefghijklmnopqrstuvwxyz  .,:;!?",D,1)->Str1
If B=2:Str1+sub("ABCDEFGHIJKLMN789RS456WX1230.,:;!?",D,1)->Str1
If length(Str1)=2 and C=0:Then
sub(Str1,2,length(Str1)-1)->Str1
1->C
End:End:End
ClrHome
//Final Display
Disp "Text Centering Tool"
Disp "X Pixel to Center On: "+Str2
Disp "Text: "+Str1
End
//Variable Assignment
" "->Str2
"i.!"->Str3
"l,:"->Str4
"s"->Str5
"ABCDEFGHIJKLOPQRSTZbcdefghjnprtvyz;?1234567890"->Str6
"NUXkoqx"->Str7
"MVWYau"->Str8
"mw"->Str9
0->dim(L1
0->dim(L2
DelVar Str0
If |LTXT(1)=0:1->|LTXT(1)
DelVar PDelVar ODelVar QDelVar RDelVar SDelVar TDelVar UDelVar UDelVar VDelVar W
1->E
~2->P

//Actual Math
For(B,1,8
expr(sub("Str2Str3Str4Str5Str6Str7Str8Str9",B,1))->Str0
length(Str0)->dim(L1
If B=7:E+1->E
If B=8:B+1->B
Fill(expr(sub("2467891012",B,E)),L1
If dim(L2)>0:augment(L2,L1)->L2
If dim(L2)=0:L1->L2
ClrList L1
End
Str2+Str3+Str4+Str5+Str6+Str7+Str8+Str9->Str0
For(X,1,length(Str1
L2(inString(Str0,sub(Str1,X,1)
Ans+P->P
End

round((|LTXT(1)-(P/2)),0)->|LTXT(3)

//Final Output
If |LTXT(2)=0:Then
{0,1}->L1
{0,|LTXT(3)}->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str0
sub(Str0,1,length(Str0)-3->Str0
DelVar {Y1}
{0,1}->L1
{0,P}->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str2
sub(Str2,1,length(Str2)-3->Str2
DelVar {Y1}
Disp "X Value: "+Str0,"Pixel Value: "+Str2
If |LTXT(4)=1:Then
Disp "Graphing Text"
rand(50
Vertical 132,Black,1
Text(82,|LTXT(3),Str1
Text(120,58,"Press Enter to Return"
Pause
ClrDraw
Disp
End:End
{0,0,|LTXT(3),|LTXT(4),|LTXT(5),|LTXT(5)}->|LTXT
Return

//Documentation:
//O=2,0;B=1
//Q=2,2;B=2
//R=4,2;B=3
//S=5,2;B=4
//T=6,2;B=5
//U=7,2;B=6
//V=8,2;B=7
//W=10,2;B=8

//If inString(Str2,sub(Str1,1,1)):Then
//For(A,1,length(Str2))
//inString(Str1,sub(Str2,A,1))
//If Ans>0:Then
//Disp Ans
//Ans+S->S
//Disp S
//End:End:End

//ALL NUMBERS ARE 6,2
//CAPITAL LETTERS
//A = 6,2
//B = 6,2
//C = 6,2
//D = 6,2
//E = 6,2
//F = 6,2
//G = 6,2
//H = 6,2
//I = 6,2
//J = 6,2
//K = 6,2
//L = 6,2
//M = 8,2
//N = 7,2
//O = 6,2
//P = 6,2
//Q = 6,2
//R = 6,2
//S = 6,2
//T = 6,2
//U = 7,2
//V = 8,2
//W = 8,2
//X = 7,2
//Y = 8,2
//Z = 6,2
//LOWERCASE:
//a = 8,2
//b = 6,2
//c = 6,2
//d = 6,2
//e = 6,2
//f = 6,2
//g = 6,2
//h = 6,2
//i = 2,2
//j = 6,2
//k = 7,2
//l = 4,2
//m = 10,2
//n = 6,2
//o = 7,2
//p = 6,2
//q = 7,2
//r = 6,2
//s = 5,2
//t = 6,2
//u = 8,2
//v = 6,2
//w = 10,2
//x = 7,2
//y = 6,2
//z = 6,2
//SYMBOLS:
//[Space] = 2,0
//. = 2,2
//, = 4,2
//; = 6,2
//: = 4,2
//! = 2,2
//? = 6,2

//Text Input Documentation:
//A:41
//B:42
//C:43
//D:51
//E:52
//F:53
//G:54
//H:55
//I:61
//J:62
//K:63
//L:64
//M:65
//N:71
//O:72
//P:73
//Q:74
//R:75
//S:81
//T:82
//U:83
//V:84
//W:85
//X:91
//Y:92
//Z:93


Reference:
Thanks Kerm and Michael for helping me on this project in the very beginning. Out of this project came the post from Michael about pixel widths on the TI Calculators. He did the monochrome, while I did the color calculators. If you want to check it out click here. Also thanks to all the people that browse the chat on Cemetech. I ask a bunch of random questions, which led to this post. Again, thanks Haobo and Kerm! I ended up using your guys' suggestions in the final product. Also thanks lirtosiast for the suggestion for shortening the code!

Also leave any suggestions for shortening, compacting, or improving the code below. As of right now the only bugs occur when you exit the program early.

Edit: Applied lirtosiast suggestion and rerecorded the gif to show new features like Help. Added more input keys including punctuation: .,:;!?

Edit 2: Added support for numbers. Added quit. Added saved settings. Improved overall experience.
Much of your program (not the I/O functionality), can be a small routine to find the width, in pixels, of Str1. I'm not sure how to code this right now, but it would be something like

Code:

sum(seq(L1(inString(Str3,sub(Str1,X,1)),1),X,1,length(Str1

where Str3 is "ABCDEF...Zabcdef...z ,.;:" and L1 is a list of the widths of all of the the individual characters in Str3; that is, {6,6,6,6,6,6,6,6,6,6,6,6,8,7,6,...}. It shouldn't take too much memory.
lirtosiast wrote:
Much of your program (not the I/O functionality), can be a small routine to find the width, in pixels, of Str1. I'm not sure how to code this right now, but it would be something like

Code:

sum(seq(L1(inString(Str3,sub(Str1,X,1)),1),X,1,length(Str1

where Str3 is "ABCDEF...Zabcdef...z ,.;:" and L1 is a list of the widths of all of the the individual characters in Str3; that is, {6,6,6,6,6,6,6,6,6,6,6,6,8,7,6,...}. It shouldn't take too much memory.


Nice Idea. I'll try it and see if it works Smile

Edit: After further testing it does work, but because I want the user to be able to add their own symbols, it doesn't compact it as much. The reason is that I have the system automatically generate a new L1 and L2 each time. You can see the comparison in the code below.


Code:
"RascalJack"->Str1
" "->Str2
"i."->Str3
"l,:"->Str4
"s"->Str5
"ABCDEFGHIJKLOPQRSTZbcdefghjnprtvyz;"->Str6
"NUXkoqx"->Str7
"MVWYau"->Str8
"mw"->Str9
1->E
0->dim(L2
~2->P
132->C
264/C->D

For(B,1,8
expr(sub("Str2Str3Str4Str5Str6Str7Str8Str9",B,1))->Str0
length(Str0)->dim(L1
If B=7:E+1->E
If B=8:B+1->B
Fill(expr(sub("2467891012",B,E)),L1
If dim(L2)>0:augment(L2,L1)->L2
If dim(L2)=0:L1->L2
ClrList L1
End
Str2+Str3+Str4+Str5+Str6+Str7+Str8+Str9->Str0
For(X,1,length(Str1
L2(inString(Str0,sub(Str1,X,1)
Ans+P->P
End

Disp (132-(P/D))


Code:
"The"->Str1
" "->Str2
"i."->Str3
"l,:"->Str4
"s"->Str5
"ABCDEFGHIJKLOPQRSTZbcdefghjnprtvyz;"->Str6
"NUXkoqx"->Str7
"MVWYau"->Str8
"mw"->Str9
0->dim(L1
DelVar Str0
132->C
264/C->D
1->E
~2->P

For(B,1,8)
expr(sub("Str2Str3Str4Str5Str6Str7Str8Str9",B,1))->Str0
For(A,1,length(Str1
inString(Str0,sub(Str1,A,1
Repeat not(Ans
If Ans>0:Then
Ans->L1(1+dim(L1)
inString(Str0,sub(Str1,A,1),Ans+1
End:End:End
If B=7:E+1->E
If B=8:B+1->B
If dim(L1:Then
dim(L1)*expr(sub("2467891012",B,E))+P->P
End
ClrList L1
End

Disp (C-(P/D))

But...if you remove the whole make it easy to edit characters, it is a whole lot more efficient. The code below gives an example. Thanks for the suggestion. It was cool to see how seq( and sum( works, but in the end I edited the idea and came up with this code. Smile

Code:
"The"->Str1
~2->P
132->C
264/C->D
" i.l,:sABCDEFGHIJKLOPQRSTZbcdefghjnprtvyz;NUXkoqxMVWYaumw"->Str0
{2,4,4,6,6,6,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,10,10,10,10,10,10,12,12}->L1
For(X,1,length(Str1
L2(inString(Str0,sub(Str1,X,1)
Ans+P->P
End
Disp (132-(P/D))
Fixed a detrimental bug where pixel value would be divided by wrong number so it would display improper values if you centered on a different X value than 132. This bug occurred because I thought that since 264/132 = 2 then P/(264/132) would be proportionally correct, but my logic was wrong since you are trying to figure out the correct pixel to center on so instead it would be P/2 subtracted from X Value to center on. Bug is fixed in the top post and pastebin.
  
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