I am trying to make a bouncing ball animation in TI Basic and The ball is leaving a trail, and I can't figure out how to clear the graph every second. Is there a solution to this problem, if so please post it.
My Code:
ClrDraw
AxesOff
0->Xmin
0->Ymin
94->Xmax
62->Ymax
Xmax/2->X
Ymax/2->Y
1->A
1->B
Line(0, Ymax, Xmax, Ymax)
Line(0, Ymax, 0, 0)
Line(0, 0, Xmax, 0)
Line(Xmax, Ymax, Xmax, 0)
While 1
If X<1 or X>Xmax-3
Then A*-1->A
End
If Y<1 or Y>Ymax-3
Then
B*-1->B
End
Line(X,Y,X+2,Y)
Line(X,Y+1,X+2,Y+1)
Line(X,Y+2,X+2,Y+2)
X+A->X
Y+B->Y
End
You have two options to clear the ball after every frame:
You can either run ClrDraw
every frame, before you draw the ball on that frame, or
you can run the code to draw the ball before you update the ball's coordinates, but instead of drawing with a black pen color, you can draw with white or set the erase flag, to erase the ball. There's an optional 5th argument to Line()
that if it's set to 0, will erase your line instead of drawing it.
You can use either to remove the "after-image" the ball keeps, but ClrDraw
will erase the whole screen, and keep nothing that you had there before, as opposed to the erasing Line()
technique, which will only erase the ball.
The code, however, is up to you to implement.