the edge of the window is at coordinate but xlow should not be or the ball would be half way off the screen before bouncingfor the edge of the ball to hit the edge of the screenthe coordinate of the center must be the length of the radius awayso actually xlow is the radius of the ball animation goes quickly in small stepsso cheat allow the ball to take one (smallquickstep past where it really should go (xlow)and then we reverse it so it comes back to where it belongs in particular if xlowdx -dx there are similar bounding variables xhighylow and yhighall the radius away from the actual edge coordinatesand similar conditions to test for bounce off each possible edge note that whichever edge is hitone coordinateeither dx or dyreverses one way the collection of tests could be written is if xlowdx -dx if xhighdx -dx if ylowdy -dy if yhighdy -dy this approach would cause there to be some extra testingif it is true that xlowthen it is impossible for it to be true that xhighso we do not need both tests together we avoid unnecessary tests with an elif clause (for both and )if xlowdx -dx elif xhighdx -dx if ylowdy -dy elif yhighdy -dy note that the middle if is not changed to an elifbecause it is possible for the ball to reach cornerand need both dx and dy reversed the program also uses several methods to read part of the state of graphics objects that we have not used in examples yet various graphics objectslike the circle we are using as the shapeknow their center pointand it can be accessed with the getcenter(method (actually clone of the point is returned also each coordinate of point can be accessed with the getx(and gety(methods this explains the new features in the central function defined for bouncing around in boxbounceinbox the animation arbitrarily goes on in simple repeat loop for steps ( later example will improve this behavior def bounceinbox(shapedxdyxlowxhighylowyhigh)''animate shape moving in jumps (dxdy)bouncing when its center reaches the low and high and coordinates ''delay for in range( )shape move(dxdy if statements