The drawing code

Listing 5 draws a black ball at the old coordinates (see Listing 4):

That erases the old image:

Then Listing 5 draws a new green ball: