Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: boot2490 on September 25, 2011, 06:06:22 pm
-
So, in homescreen invaders, the alien fleet is rendered by the program reading from a 3X5 matrix and drawing a V in the appropriate position.
Howver, it doesn't draw anything.
Also, the matrix is appropriately filled with 1's for the example.
Here is the code:
1→M
1→X
1→Y
While M≤15
If X≤5
Then
If Y≤3
Then
If [I](Y,X)=1
Output(Y+3,X+3,"V"
If [I](Y,X)=0
Output(Y+3,X+3," "
Else
Goto Z
End
Else
X+1→X
Y+1→Y
End
M+1→M
End
-
Nevermind whatever I had here at first. I was being stupid. Um... I'm going to use my own method (but retain some of the same things of yours) because I despise while loops unless I'm reading from a file on the computer... This method will also allow you to change the size of the matrix at any time.
dim([I]→L1
Ans(1→H
L1(2→W
For(Y,1,H)
For(X,1,W)
If [I](Y,X)=1
Output(Y+3,X+3,"V
If not([I](Y,X
Output(Y+3,X+3," "
End
End
DelVar L1
-
Please don't put a loop after a DelVar. It will then be skipped if something like an if statement surrounds it. ;)
Also, if you close the parenthesis on the For loops, it'll run faster (because TI fails).
-
That is a lot of less lines. How does it work? Must know...
-
@ztrumpet, Ahh. I haven't really done anything with TI-BASIC in a looong time, so sorry about that lol. I just did it the way Is do it on the computer.
-
Woo I'm late to this thread. That code works like this:
the outer for increments once each time the inner for finishes, so it reads the matrix row by row. The conditionals use the values in the for loops to correspond to coordinates in the matrix, and the outputs use those coordinates to place the characters where they belong on screen in relation to the current y,x of the loops.
-
dim([I]
For(Y,1,Ans(1
For(X,1,Ans(2
If [I](Y,X
Then
Output(Y+3,X+3,"V
Else
Output(Y+3,X+3,"_
End
End
End
DelVar L1
-
Perhaps you can clarify for me then, meishe. Does the calculator pre-determine the min and max values for for loops?
-
Do you mean it that it determines the variables then store them somewhere?
-
Basically, yeah. Like, if I do
5
For(A,1,Ans
2
End
will it use 5 as the max instead of 2?
-
Dim([I]
Returns the dimensions of matrix I in ans in list format so the length and width can be recalled as ans(#
-
I know that (if that was meant for me), but my question was if the calculator remembers that as Ans for the for loop instead of something inside of the loop.
-
Ya, I believe it will. I mean it works in my example anyways :P I believe the only way to effect how the For() counts is if you modify the variable it uses. So say you have For(A,1,100):A+1→A:End, I believe it will actually be counting by two instead of by one. (Note: I haven't actually tested that, so I could be wrong. But the principle remains the same.)
-
Perhaps you can clarify for me then, meishe. Does the calculator pre-determine the min and max values for for loops?
I'm actually not sure. Meishe's example works because Ans is never changed during the loops.
-
Quick Wabbit test shows that
5
For(A,1,Ans
2
Disp Ans
End
Displays "2" five times. So maybe? :D