patternMinor
TI-Basic Bouncing Ball Animation
Viewed 0 times
ballbouncinganimationbasic
Problem
Anyone who has programmed in TI-Basic is likely to have written one of these programs. The concept for this program is simple.
The "ball" represented by a single point that originates from the upper left hand corner of the screen and bounces around the screen leaving a trail as it travels. The initial movement vector for the ball is (1,1), meaning one down, one right. During each pass through a loop, the "ball" is translated by the amount specified in the movement vector. When the ball would go of bounds, its movement vector is adjusted so that this does not happen. In short, it behaves like this:
except I increased the frame of the GIF.
I've reduced my code to a very short and clean snippet:
What I would like to hear in responses can be enumerated in four points:
People responding to this post should also keep in mind that this code was written for and tested on a TI-83 Plus calculator.
The "ball" represented by a single point that originates from the upper left hand corner of the screen and bounces around the screen leaving a trail as it travels. The initial movement vector for the ball is (1,1), meaning one down, one right. During each pass through a loop, the "ball" is translated by the amount specified in the movement vector. When the ball would go of bounds, its movement vector is adjusted so that this does not happen. In short, it behaves like this:
except I increased the frame of the GIF.
I've reduced my code to a very short and clean snippet:
FnOff
PlotsOff
AxesOff
ClrDraw
{1,1→L₁
Repeat getKey
Ans→L₂
Pxl-Change(L₁(1),L₁(2
Ans+L₁→L₁
L₂*(1-2not(Ans and Ans≠{62,94
End
FnOn
PlotsOn
AxesOn
ClrDrawWhat I would like to hear in responses can be enumerated in four points:
- How can I reduce the size of this program?
- How can I increase the speed of this program?
- How can I reduce the numbers of variables used in this program?
- How can I increase the clarity of this program without sacrificing any of the goals stated above?
People responding to this post should also keep in mind that this code was written for and tested on a TI-83 Plus calculator.
Solution
On my TI-82, I get an
Apparently, the TI-82 does not support operations
I recommend that you avoid relying on
ERR:DATA TYPE on the following line:L₂*(1-2not(Ans and Ans≠{62,94Apparently, the TI-82 does not support operations
not and and on lists.I recommend that you avoid relying on
Ans. Stating what you mean explicitly leads to less code that is less fragile and more readable. The following code also has one fewer statement within the loop.{1,1→L₁
L₁→L₂
Repeat getKey
Pxl-Change(L₁(1),L₁(2
L₂+2(L₁={0,0})-2(L₁={62,94}→L₂
L₁+L₂→L₁
EndCode Snippets
L₂*(1-2not(Ans and Ans≠{62,94{1,1→L₁
L₁→L₂
Repeat getKey
Pxl-Change(L₁(1),L₁(2
L₂+2(L₁={0,0})-2(L₁={62,94}→L₂
L₁+L₂→L₁
EndContext
StackExchange Code Review Q#82847, answer score: 4
Revisions (0)
No revisions yet.