1

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

Boo Boo
  • 80
  • 9

3 Answers3

3

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.

Stephen P
  • 195
  • 11
0

One option that I have used in the past is to render blank all around the object's sides that are leaving trails.

I believe it's the left and top that leave trails, so you can simply draw a blank nothing to the left and above where the ball is rendered, effectively erasing the trail on the fly.

Another option is to use ClrDraw every iteration, but this is highly inefficient on the processor, and will slow down the animation.

Aashishkebab
  • 295
  • 3
  • 10
0

You can use ClrDraw, however, it slows the program tremendously, so it is better to use redraw the ball with the last argument as 0 to clear traces, and only use ClrDraw once before the main loop.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zenedus
  • 96
  • 9