Michael2_3B wrote:
Nice job doing the transformations and stuff, but you are repeating A LOT of code throughout your program. It would be better to do something like:

Code:

(Menu)

(Translation code)
Goto EE

(Reflection code)
Goto EE

(Rotation code)
Goto EE

(Dilation code)

Lbl EE   //use whatever label you want
(New points code)
Goto Menu

I don't know what your program flow is exactly (p.s. it gets confusing when you're hopping around with Goto's), but if there is code that is exactly the same for all transformations, you should just do something along the lines of what I wrote above.

Also, I would say to avoid using Labels whenever you can, but since your a noob I think it would be simpler for you to use them right now. Later down the road however, you will probably find yourself using them less often.


Thanks for your help...but what you have mentioned is already how the program works...

This is my program flow:



Any ideas now?
I agree with Michael2_3B.
With your existing code you are storing the points into 4 lists: X (L1), Y L(2), X' (L3), and Y' (L4). Instead of displaying the value of the points within each block, you can jump to one block that does the job. Instead of having 4 blocks of code to display the points, you have one. Think of this like a funnel.

By the way, nice program flowchart! Diagrams will certainly help. Smile
Nice work on getting this far! I'm working on optimizing your code; here's one main section that I've done; I'll explain it and then you can try and apply it to other parts of your code.

So for your rotation section, I first store the Alphabet into Str1, which will eventually save space overall by a ton. Then, rather than jumping to a a section of code to run, the Menu() command jumps to a label which stores the value in M. That way when it runs through the code, it can check M and figure out what to do with the list. This is the important part:

Code:
If M=1
Then
L₂→L₃
⁻L₁→L₄
End
If M=2
Then
⁻L₁→L₃
⁻L₂→L₄
End
If M=3
Then
⁻L₂→L₃
L₁→L₄
End

This checks M and then figures out what to do with the list. If M=Some Number:Then means to execute commands until it hits an end block.

Code:
Lbl 3                                              //"Rotation" starts here
ClrHome
"ABCDEFGHIJKLMNOPQRSTUVWXYZ->Str1
0
Menu("Select your Rotation:","CW 90 (CCW 270)",31,"180",32,"CCW 90 (CW 270)",33,"Go Back",W,"Exit",Z)
Lbl 33:1
Lbl 32:Ans+1
Lbl 31:Ans+1->M

"CCW 90 (CW 270)
If M=1:"CW 90 (CCW 270)
If M=2:"180

ClrHome
Output(1,5,Ans
ClrList L₁,L₂,L₃,L₄
Disp "","","How many points are there?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
1→B
ClrHome
For(A,1,D
Disp "Point"
Output(B,7,sub(Str1,A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End
If M=1
Then
L₂→L₃
⁻L₁→L₄
End
If M=2
Then
⁻L₁→L₃
⁻L₂→L₄
End
If M=3
Then
⁻L₂→L₃
L₁→L₄
End
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub(Str1,A,1
Output(B,8,"'
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
Pause "
Menu("Plot the Images?","Yes",UB,"New Points",3,"Return to Main Menu",W,"Exit",Z

Nice work on sticking with this; you are definitely getting there! Very Happy That code should chop off 2/3 of your rotation section. Smile
After trying to implement Michael2_3B's and MateoConLechuga's tips, I came up with some crap which is again giving me problems. I tried to fix it with different methods but its not working...

(I have used Lbl all over my program, so dont freak out after seeing that. By the way, the program goes like a "funnel". I'm not making it jump around.)

Problem: Everything is going fine till "Lbl ZZ", after that i have placed conditions "If..Then" (total of 9 conditions).

So when I run "Translation" it works fine because I think that it is the first thing that comes after "Lbl ZZ", but if I try to run "Reflection" (which is defined as "L=1", I return with all the L3 and L4 values being "0". But according to my program they should return with "some" other values.

According to me, it is basically skipping my argument and going ahead.

What is happening? Please help me?


Code:

Lbl W
Menu("Select your Tranformation:","Translation",1,"Reflection",2,"Rotation",3,"Dilation",4,"Exit",Z)

ClrList L₁,L₂,L₃,L₄
DelVar M
DelVar L
DelVar K
DelVar J
DelVar I
DelVar H
DelVar G
DelVar F
DelVar E

Lbl 1
Goto AA

Lbl 2
Goto BB

Lbl 3
Goto CC
 
Lbl 4
Goto DD

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Select your Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B2,"Y=-x",B2,"Go Back",W,"Exit",Z)

Lbl B1
Goto B5

Lbl B2
Goto B6

Lbl B3
Goto B7

Lbl B4
Goto B8

Lbl B5
1→L
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B6
1→K
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B7
1→J
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B8
1→I
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Select your Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
Goto C4

Lbl C2
Goto C5

Lbl C3
Goto C6

Lbl C4
1→H
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C5
1→G
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C6
1→F
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Select your Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
Goto D2

Lbl D2
1→E
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","How many points are there?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End

If M=1
Then
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
End
Goto ZY

If L=1
Then
L₁→L₃
⁻L₂→L₄
End
Goto ZY

If K=1
Then
⁻L₁→L₃
L₂→L₄
End
Goto ZY

If J=1
Then
L₂→L₃
L₁→L₄
End
Goto ZY

If I=1
Then
⁻L₂→L₃
⁻L₁→L₄
End
Goto ZY

If H=1
Then
L₂→L₃
⁻L₁→L₄
End
Goto ZY

If G=1
Then
⁻L₁→L₃
⁻L₂→L₄
End
Goto ZY

If F=1
Then
⁻L₂→L₃
L₁→L₄
End
Goto ZY

If E=1
Then
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
End
Goto ZY

Lbl ZY
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
Goto ZW

Lbl ZW
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

If M=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",AA,"Return to Main Menu",W,"Exit",Z)
End

If L=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If K=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If J=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If I=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If H=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If G=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If F=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If E=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",DD,"Return to Main Menu",W,"Exit",Z)
End

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W
Okay, I think there are more problems in your code than you actually realize...

Code:

Lbl W 
Menu("Select your Tranformation:","Translation",1,"Reflection",2,"Rotation",3,"Dilation",4,"Exit",Z)

ClrList L₁,L₂,L₃,L₄
DelVar M
DelVar L
DelVar K
DelVar J
DelVar I
DelVar H
DelVar G
DelVar F
DelVar E

Here, the code that comes after the Menu will always be skipped, because selecting one of the options in the menu will make it jump to that label (so if you picked Translation, it would skip all that code after the menu and go to label 1). It would be better to move the code after the menu to before the menu, so that it actually runs.

Also just a little tip to save a little bit of mem:

Code:

:DelVar M
:DelVar L
:DelVar K
:DelVar J
:DelVar I
:DelVar H
:DelVar G
:DelVar F
:DelVar E

can be

Code:

:DelVar MDelVar LDelVar KDelVar JDelVar IDelVar HDelVar GDelVar FDelVar E

this is because the DelVar command doesn't require a new line of code. You can just place one after another without any colons in between.

Another optimization:
in some places you have
:If (condition)
:Then
(1 line of code)
:End
just a tip, when you only have 1 line of code if (condition) is true, you don't need the "Then" and "End". The If command will always run the line of code directly after it if (condition) is true. However, if you are wanting to run multiple lines of code if (condition) is true, that's when you would use If...Then...End.
------------------------------------------------------------------------------------------------------
Here's something else:

Code:

Lbl 1
Goto AA

Lbl 2
Goto BB

Lbl 3
Goto CC
 
Lbl 4
Goto DD

instead of doing this, couldn't you just replace

Code:

Menu("Select your Tranformation:","Translation",1,"Reflection",2,"Rotation",3,"Dilation",4,"Exit",Z)

with this?

Code:

Menu("Select your Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)

There are some other places in your code that I think you might be able to do the same thing.
----------------------------------------------------------------------------------------------------------------------------------
As for label ZZ, I'll let someone else handle that. It's not because I don't know how to handle it, but I got some stuff to do IRL... Smile Smile
Michael2_3B wrote:

As for label ZZ, I'll let someone else handle that. It's not because I don't know how to handle it, but I got some stuff to do IRL... Smile Smile


Fixing that is currently my most important thing because "optimizations" can be done after fixing that...

Anyways thanks for your optimization...

Please try to fix it?
Quote:
Please try to fix it?
Please read this:
http://www.catb.org/esr/faqs/smart-questions.html
Could you post your latest code by any chance? It would be easier to determine the source of the problem that way. Thanks! Smile
MateoConLechuga wrote:
Could you post your latest code by any chance? It would be easier to determine the source of the problem that way. Thanks! Smile


Here is my latest code and problem:

AkonSpy wrote:
After trying to implement Michael2_3B's and MateoConLechuga's tips, I came up with some crap which is again giving me problems. I tried to fix it with different methods but its not working...

(I have used Lbl all over my program, so dont freak out after seeing that. By the way, the program goes like a "funnel". I'm not making it jump around.)

Problem: Everything is going fine till "Lbl ZZ", after that i have placed conditions "If..Then" (total of 9 conditions).

So when I run "Translation" it works fine because I think that it is the first thing that comes after "Lbl ZZ", but if I try to run "Reflection" (which is defined as "L=1", I return with all the L3 and L4 values being "0". But according to my program they should return with "some" other values.

According to me, it is basically skipping my argument and going ahead.

What is happening? Please help me?


Code:

Lbl W
Menu("Select your Tranformation:","Translation",1,"Reflection",2,"Rotation",3,"Dilation",4,"Exit",Z)

ClrList L₁,L₂,L₃,L₄
DelVar M
DelVar L
DelVar K
DelVar J
DelVar I
DelVar H
DelVar G
DelVar F
DelVar E

Lbl 1
Goto AA

Lbl 2
Goto BB

Lbl 3
Goto CC
 
Lbl 4
Goto DD

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Select your Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B2,"Y=-x",B2,"Go Back",W,"Exit",Z)

Lbl B1
Goto B5

Lbl B2
Goto B6

Lbl B3
Goto B7

Lbl B4
Goto B8

Lbl B5
1→L
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B6
1→K
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B7
1→J
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B8
1→I
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Select your Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
Goto C4

Lbl C2
Goto C5

Lbl C3
Goto C6

Lbl C4
1→H
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C5
1→G
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C6
1→F
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Select your Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
Goto D2

Lbl D2
1→E
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","How many points are there?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End

If M=1
Then
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
End
Goto ZY

If L=1
Then
L₁→L₃
⁻L₂→L₄
End
Goto ZY

If K=1
Then
⁻L₁→L₃
L₂→L₄
End
Goto ZY

If J=1
Then
L₂→L₃
L₁→L₄
End
Goto ZY

If I=1
Then
⁻L₂→L₃
⁻L₁→L₄
End
Goto ZY

If H=1
Then
L₂→L₃
⁻L₁→L₄
End
Goto ZY

If G=1
Then
⁻L₁→L₃
⁻L₂→L₄
End
Goto ZY

If F=1
Then
⁻L₂→L₃
L₁→L₄
End
Goto ZY

If E=1
Then
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
End
Goto ZY

Lbl ZY
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
Goto ZW

Lbl ZW
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

If M=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",AA,"Return to Main Menu",W,"Exit",Z)
End

If L=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If K=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If J=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If I=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)
End

If H=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If G=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If F=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)
End

If E=1
Then
Menu("Plot the Images?","Yes",ZX,"New Points",DD,"Return to Main Menu",W,"Exit",Z)
End

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W
Well...after 1 hour of intense non-stop work, I managed to fix the problem mentioned in the last post by myself (Thanks to KermMartian for motivating me on doing it myself Smile)

I also optimized the program (Many thanks to Electromagnet8, MateoConLechuga, Michael2_3B, and of course KermMartian for giving me wonderful tips that made this possible).

The original program spanned 500 lines and was around 6000 bytes!

The optimized program now spans around 200 lines and the size is reduced to only 2711 bytes! Geeez!

Further ahead, I request any one of you to try optimize the current program so that it becomes more stable and runs more efficiently without lags.

I know that I shouldn't be asking you guys to do this, but what I did now is the "most" I can do.

I'm doing this simple project just because non of the programs out there do particularly what my program does. This program will surely help people out there those who are scavenging for this program.

Please help me out. Any help will be much appreciated.


Code:

Lbl W
Menu("Select your Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Select your Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B3,"Y=-x",B4,"Go Back",W,"Exit",Z)

Lbl B1
2→M
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B2
3→M
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B3
4→M
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B4
5→M
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Select your Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
6→M
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C2
7→M
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C3
8→M
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Select your Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
9→M
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","How many points are there?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End
Goto UU

Lbl UU
If M=1
Goto U1
If M=2
Goto U2
If M=3
Goto U3
If M=4
Goto U4
If M=5
Goto U5
If M=6
Goto U6
If M=7
Goto U7
If M=8
Goto U8
If M=9
Goto U9

Lbl U1
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
Goto ZY

Lbl U2
L₁→L₃
⁻L₂→L₄
Goto ZY

Lbl U3
⁻L₁→L₃
L₂→L₄
Goto ZY

Lbl U4
L₂→L₃
L₁→L₄
Goto ZY

Lbl U5
⁻L₂→L₃
⁻L₁→L₄
Goto ZY

Lbl U6
L₂→L₃
⁻L₁→L₄
Goto ZY

Lbl U7
⁻L₁→L₃
⁻L₂→L₄
Goto ZY

Lbl U8
⁻L₂→L₃
L₁→L₄
Goto ZY

Lbl U9
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
Goto ZY

Lbl ZY
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
Goto ZW

Lbl ZW
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

If M=1
Menu("Plot the Images?","Yes",ZX,"New Points",AA,"Return to Main Menu",W,"Exit",Z)

If M=2
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=3
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=4
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=5
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=6
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=7
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=8
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=9
Menu("Plot the Images?","Yes",ZX,"New Points",DD,"Return to Main Menu",W,"Exit",Z)

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W

Lbl Z
ClrHome
Stop
At the end of your code when you ask wether to graph the transformation or not you could do something like this:


Code:
 
If M<6 and M>1
Menu code

If M=1
different menu code

If M<9 and M>5
other menu code

If M=9
last menu code
Okay, here's one optimization:

Code:

If M=1
Menu("Plot the Images?","Yes",ZX,"New Points",AA,"Return to Main Menu",W,"Exit",Z)

If M=2
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=3
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=4
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=5
Menu("Plot the Images?","Yes",ZX,"New Points",BB,"Return to Main Menu",W,"Exit",Z)

If M=6
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=7
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=8
Menu("Plot the Images?","Yes",ZX,"New Points",CC,"Return to Main Menu",W,"Exit",Z)

If M=9
Menu("Plot the Images?","Yes",ZX,"New Points",DD,"Return to Main Menu",W,"Exit",Z)


can be


Code:

Menu("Plot Images?","Yes",ZX,"New Points",NP,"Main Menu",W,"Exit",Z  //you don't have to use NP, use any Lbl u want

Lbl NP
If M=1
Goto AA
If M>=2 and M<=5
Goto BB
If M>=6 and M<=8
Goto CC
If M=9
Goto DD
Thanks guys for for your help Smile

The program is reduced from 2711 bytes to just 1850 bytes! Cool

Any further optimization will be MUCH appreciated!

I have reproduced the code below:


Code:

Lbl W
Menu("Select your Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Select your Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B3,"Y=-x",B4,"Go Back",W,"Exit",Z)

Lbl B1
2→M
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B2
3→M
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B3
4→M
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B4
5→M
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Select your Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
6→M
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C2
7→M
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C3
8→M
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Select your Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
9→M
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","How many points are there?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End
Goto UU

Lbl UU
If M=1
Goto U1
If M=2
Goto U2
If M=3
Goto U3
If M=4
Goto U4
If M=5
Goto U5
If M=6
Goto U6
If M=7
Goto U7
If M=8
Goto U8
If M=9
Goto U9

Lbl U1
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
Goto ZW

Lbl U2
L₁→L₃
⁻L₂→L₄
Goto ZW

Lbl U3
⁻L₁→L₃
L₂→L₄
Goto ZW

Lbl U4
L₂→L₃
L₁→L₄
Goto ZW

Lbl U5
⁻L₂→L₃
⁻L₁→L₄
Goto ZW

Lbl U6
L₂→L₃
⁻L₁→L₄
Goto ZW

Lbl U7
⁻L₁→L₃
⁻L₂→L₄
Goto ZW

Lbl U8
⁻L₂→L₃
L₁→L₄
Goto ZW

Lbl U9
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
Goto ZW

Lbl ZW
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

Menu("Plot the Images?","Yes",ZX,"New Points",NP,"Main Menu",W,"Exit",Z

Lbl NP
If M=1
Goto AA
If M≥2 and M≤5
Goto BB
If M≥6 and M≤8
Goto CC
If M=9
Goto DD

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W

Lbl Z
ClrHome
Stop
okay, another thing I noticed: you have 2 Lbl UU's. you should change one of them to something else. Also when you have something like

Code:

:Goto UU

:Lbl UU

you should just get rid of the Goto UU, because that same label is directly after it.

and since both of your UU's do the same exact thing, you should just get rid of the code I mentioned above all together.

so instead of

Code:

(code)
Goto UU

Lbl UU
(code)

you should just do

Code:

(code)

(code)


Also, a little lesson about Lbl's: when you have a Goto command, it searches for the Label specified after Goto starting at the beginning of the program and stops searching when it finds your label. so if you have two labels in the same program, and you Goto that label, it will always be the first one that appears in the program - you'll never be able to get to the second one.
Thanks Micheal!!!

Saved another 100 bytes!

The program got reduced from 1850 bytes to 1742 bytes. Cool

Is there anything more possible?

Just a curious question: In the past, you said me that using Lbls is not a good choice. Are there any alternatives to Lbl? Why shouldn't Lbl be used?


Code:

Lbl W
Menu("Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B3,"Y=-x",B4,"Go Back",W,"Exit",Z)

Lbl B1
2→M
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B2
3→M
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B3
4→M
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B4
5→M
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
6→M
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C2
7→M
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C3
8→M
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
9→M
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","Number of Points?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End

If M=1
Goto U1
If M=2
Goto U2
If M=3
Goto U3
If M=4
Goto U4
If M=5
Goto U5
If M=6
Goto U6
If M=7
Goto U7
If M=8
Goto U8
If M=9
Goto U9

Lbl U1
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
Goto ZW

Lbl U2
L₁→L₃
⁻L₂→L₄
Goto ZW

Lbl U3
⁻L₁→L₃
L₂→L₄
Goto ZW

Lbl U4
L₂→L₃
L₁→L₄
Goto ZW

Lbl U5
⁻L₂→L₃
⁻L₁→L₄
Goto ZW

Lbl U6
L₂→L₃
⁻L₁→L₄
Goto ZW

Lbl U7
⁻L₁→L₃
⁻L₂→L₄
Goto ZW

Lbl U8
⁻L₂→L₃
L₁→L₄
Goto ZW

Lbl U9
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
Goto ZW

Lbl ZW
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

Menu("Plot the Images?","Yes",ZX,"New Points",NP,"Main Menu",W,"Exit",Z)

Lbl NP
If M=1
Goto AA
If M≥2 and M≤5
Goto BB
If M≥6 and M≤8
Goto CC
If M=9
Goto DD

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W

Lbl Z
ClrHome
Stop
So, just as a thought, instead of having 'select your dilation' and just 'from the origin', if you instead ask for a dilation centerpoint, then translate every point (including the dilation centerpoint) so that the centerpoint is at the origin, then you can use your code for Lbl D1. All you need to do is translate them back.
Effectively, what this is doing is translating the axes, then dilating the points, then resetting the axes' positions.
Another thing:

Code:
End
Goto UU

Lbl UU

One thing to consider when optimizing is this: can the program work as it's supposed to without that line? In this case, if you take out both the Goto and the Lbl, nothing will change. Since it's never going to go to UU without going to ZZ first, then you can remove both. another thing: in the Lbl UU bracket, you have instructions for every M-value. if you take out the first one, if M>9 or M<2, then it'll automagically go to Lbl U1. Again, you could remove the Lbl U1 as well.
Even more: The command line evaluates algebraic equations and returns outputs in binary. For example, (U=2), if U=2, would return a (1), but if U≠2, it would return 0. this means, that you can condense your Lbl U* section. For example,

Code:
Lbl U2
L₁→L₃
⁻L₂→L₄
Goto ZW

Lbl U3
⁻L₁→L₃
L₂→L₄
Goto ZW


      This could be:

Lbl U2
L₁-2*L₁(M=3→L₃
L₂-2*L₂(M=2→L₄
Goto ZW

Also, in answer to your last question, yes, there are alternatives, namely Repeat and While. they're both used like If. Repeat will go until the condition is true, while until false. they each have some idiosyncrasies you'll have to read up on.
If you read http://tibasicdev.wikidot.com/lbl, it states some of the reasons why using Lbl's isn't the best option Smile
Let me try my hand at converting the Lbl U*s to boolean:

Code:
(M=2)L₁-(M=3)L₁+(M=4)L₂-(M=5)L₂+(M=6)L₂-(M=7)L₁-(M=8)L₂→L₃

Here's the first half for U2 through U8.
JLovern wrote:
Let me try my hand at converting the Lbl U*s to boolean:

Code:
(M=2)L₁-(M=3)L₁+(M=4)L₂-(M=5)L₂+(M=6)L₂-(M=7)L₁-(M=8)L₂→L₃

Here's the first half for U2 through U8.


Thanks for your efforts. But what you just did just went over the top of my head Confused

Anyways, while I was away I worked on the program a little but and reduced the size to 1656 bytes. Cool


Code:

Lbl W
Menu("Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)

Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ

Lbl BB
ClrHome
Menu("Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B3,"Y=-x",B4,"Go Back",W,"Exit",Z)

Lbl B1
2→M
ClrHome
Output(1,10,"X-axis
Goto ZZ

Lbl B2
3→M
ClrHome
Output(1,10,"Y-axis
Goto ZZ

Lbl B3
4→M
ClrHome
Output(1,12,"Y=x
Goto ZZ

Lbl B4
5→M
ClrHome
Output(1,11,"Y=-x
Goto ZZ

Lbl CC
ClrHome
Menu("Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)

Lbl C1
6→M
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ

Lbl C2
7→M
ClrHome
Output(1,11,"180°
Goto ZZ

Lbl C3
8→M
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ

Lbl DD
ClrHome
Menu("Dilation:","From the Origin",D1,"Go Back",W,"Exit",Z)

Lbl D1
9→M
ClrHome
Output(1,6,"From the Origin
Goto ZZ

Lbl ZZ
Disp "","","Number of Points?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End

If M=1
Then
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
End
If M=2
Then
L₁→L₃
⁻L₂→L₄
End
If M=3
Then
⁻L₁→L₃
L₂→L₄
End
If M=4
Then
L₂→L₃
L₁→L₄
End
If M=5
Then
⁻L₂→L₃
⁻L₁→L₄
End
If M=6
Then
L₂→L₃
⁻L₁→L₄
End
If M=7
Then
⁻L₁→L₃
⁻L₂→L₄
End
If M=8
Then
⁻L₂→L₃
L₁→L₄
End
If M=9
Then
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
End
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause

Menu("Plot the Images?","Yes",ZX,"New Points",NP,"Main Menu",W,"Exit",Z)

Lbl NP
If M=1
Goto AA
If M≥2 and M≤5
Goto BB
If M≥6 and M≤8
Goto CC
If M=9
Goto DD

Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W

Lbl Z
ClrHome
Stop
JLovern wrote:
So, just as a thought, instead of having 'select your dilation' and just 'from the origin', if you instead ask for a dilation centerpoint, then translate every point (including the dilation centerpoint) so that the centerpoint is at the origin, then you can use your code for Lbl D1. All you need to do is translate them back.
Effectively, what this is doing is translating the axes, then dilating the points, then resetting the axes' positions.


Could you please elaborate and explain me this? I dont understand in the way that it is currently written. I really want to have an option for custom origin, but I dont have any idea on how to approach it Confused

------------------------------------------------------------------------------------------

Update: Thanks for you help, Jlovern. I figured the math out myself. Cool Good Idea

For any of you those who are looking for my latest code, here it is:

(P.S. If you can please try optimizing it...)


Code:

Lbl W
Menu("Tranformation:","Translation",AA,"Reflection",BB,"Rotation",CC,"Dilation",DD,"Exit",Z)
Lbl AA
1→M
ClrHome
Output(1,8,"Translation
Goto ZZ
Lbl BB
ClrHome
Menu("Reflection:","X-axis",B1,"Y-axis",B2,"Y=x",B3,"Y=-x",B4,"Go Back",W,"Exit",Z)
Lbl B1
2→M
ClrHome
Output(1,10,"X-axis
Goto ZZ
Lbl B2
3→M
ClrHome
Output(1,10,"Y-axis
Goto ZZ
Lbl B3
4→M
ClrHome
Output(1,12,"Y=x
Goto ZZ
Lbl B4
5→M
ClrHome
Output(1,11,"Y=-x
Goto ZZ
Lbl CC
ClrHome
Menu("Rotation:","CW 90° (CCW 270°)",C1,"180°",C2,"CCW 90° (CW 270°)",C3,"Go Back",W,"Exit",Z)
Lbl C1
6→M
ClrHome
Output(1,5,"CW 90° (CCW 270°)
Goto ZZ
Lbl C2
7→M
ClrHome
Output(1,11,"180°
Goto ZZ
Lbl C3
8→M
ClrHome
Output(1,5,"CCW 90° (CW 270°)
Goto ZZ
Lbl DD
ClrHome
Menu("Dilation:","From the Origin",D1,"Custom Origin",D2,"Go Back",W,"Exit",Z)
Lbl D1
9→M
ClrHome
Output(1,6,"From the Origin
Goto ZZ
Lbl D2
10→M
ClrHome
Output(1,7,"Custom Origin
Goto ZZ
Lbl ZZ
Disp "","","Number of Points?","
Prompt D
D→dim(L₁
D→dim(L₂
D→dim(L₃
D→dim(L₄
ClrHome
1→B
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
B+3→B
If B>9
9→B
Prompt X
X→L₁(A
Prompt Y
Y→L₂(A
End
If M=1
Then
ClrHome
Disp "Move By?","
Prompt X
X+L₁→L₃
Prompt Y
Y+L₂→L₄
End
If M=2
Then
L₁→L₃
⁻L₂→L₄
End
If M=3
Then
⁻L₁→L₃
L₂→L₄
End
If M=4
Then
L₂→L₃
L₁→L₄
End
If M=5
Then
⁻L₂→L₃
⁻L₁→L₄
End
If M=6
Then
L₂→L₃
⁻L₁→L₄
End
If M=7
Then
⁻L₁→L₃
⁻L₂→L₄
End
If M=8
Then
⁻L₂→L₃
L₁→L₄
End
If M=9
Then
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
L₁*E→L₃
L₂*E→L₄
End
If M=10
Then
ClrHome
Output(1,7,"Scale Factor?
Disp "","
Prompt E
ClrHome
Output(1,4,"Center of Dilation?
Disp "","
Prompt X,Y
L₁-X→L₅
L₂-Y→L₆
L₅*E→L₅
L₆*E→L₆
L₅+X→L₃
L₆+Y→L₄
End
augment(L₁,{L₁(1→L₁
augment(L₂,{L₂(1→L₂
augment(L₃,{L₃(1→L₃
augment(L₄,{L₄(1→L₄
ClrHome
2→B
Output(1,8,"New Points: "
Disp ""
For(A,1,D
Disp "Point"
Output(B,7,sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",A,1
Output(B,8,sub("''''''''''''''''''''''''''",A,1
B+2→B
If B>9
9→B
Disp {L₃(A),L₄(A)
End
"
Pause
Menu("Plot the Images?","Yes",ZX,"New Points",NP,"Main Menu",W,"Exit",Z)
Lbl NP
If M=1
Goto AA
If M≥2 and M≤5
Goto BB
If M≥6 and M≤8
Goto CC
If M≥9
Goto DD
Lbl ZX
Plot1(xyLine,L₁,L₂,plotsquare)
Plot2(xyLine,L₃,L₄,plotsquare)
DispGraph
ZStandard
Pause
ClrDraw
PlotsOff
Goto W
Lbl Z
ClrHome
Stop
  
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 3 of 4
» 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