line(point( lineheight)point(win getwidth()lineheight)draw(winprompt 'click above the line to stop\nor below to move toward the click text(point(win getwidth()/ textheight)promptdraw(winradius xlow radius center is separated from the wall by the radius at bounce xhigh win getwidth(radius ylow radius yhigh lineheight radius #new lower top to bouncing limits center point(win getwidth()/ lineheight/ ball makedisk(centerradiuswinmoveinbox(balllineheightxlowxhighylowyhighwin#new win close(bounceball( initially made only the changes discussed so far (not the ones involving the new variable isinsidethe variable isinside was in response to bug that will discuss after introducing the simple function that wraps around bounceinboxeach time the mouse is clickedthe ball is to switch direction and move toward the last clickuntil the stopping condition occurswhen there is click above the stop line this is clearly repetitive and needs while loop the condition is simply to test the coordinate of the mouse click against the the height of the stop line the body of the loop is very shortsince we already have the utility function getshiftto figure out (dxdyvalues def moveinbox(shapestopheightxlowxhighylowyhighwin)#new '''shape bounces in win so its center stays within the low and high and coordinatesand changes direction based on mouse clicksterminating when there is click above stopheight ''scale pt shape getcenter(starts motionless while pt gety(stopheight(dxdygetshift(shape getcenter()ptpt bounceinbox(shapedx*scaledy*scalexlowxhighylowyhighwinthe variable pt for the last mouse click needed to be initialized some way chose to make the value be the same as the initial position of the ballso both dx and dy are initially and the ball does not start in motion (alternatives are in random start exercise (page below occasionally detected bug when using the program the ball would get stuck just outside the boundary and stay there the fact that it was slightly beyond the boundary was cluefor simplicity had cheatedand allowed the ball to go just one animation step beyond the intended boundary with the speed and small step size this works visually the original code was sure to make an opposite jump back inside at the next step after some thoughti noticed that the initial version of the bounce py code for bounceinbox broke that assumption when the ball was where bounce-back is requireda mouse click could change (dxdyand mess up the bounce the idea for fix is not to let the user change the direction in the moment when the ball needs to bounce back neither of the original boundary-checking if statementsby itselfalways determines if the ball is in the region where it needs to reverse direction dealt with this situation by introducing boolean variable isinside it is initially set as trueand then either of the if statements can correct it to false thenat the end of the loopisinside is used to make sure the ball is safely inside the proper region when there is check for new mouse click and possible user adjustment to (dxdy while statements