displaysurf blit(newbgsurf( )drawbuttons(redraw the buttons on top of the tint pygame display update(fpsclock tick(fpsbgcolor newbgcolor the background color change animation happens whenever the player finishes entering the entire pattern correctly on each iteration through the loop which starts on line the entire display surface has to be redrawn (blended with less and less transparent new background coloruntil the background is completely covered by the new colorthe steps done on each iteration of the loop areline fills in the entire display surface (stored in displaysurfwith the old background color (which is stored in bgcolorline fills in different surface object (stored in newbgsurfwith the new background color' rgb values (and the alpha transparency value changes on each iteration since that is what the for loop on line doesline then draws the newbgsurf surface to the display surface in displaysurf the reason we didn' just paint our semitransparent new background color on displaysurf to begin with is because the fill(method will just replace the color on the surfacewhereas the blit(method will blend the colors now that we have the background the way we want itwe'll draw the buttons over it with call to drawbuttons(on line line and then just draws the display surface to the screen and adds pause the reason there is global statement at the beginning of the changebackgroundanimation(function is for the bgcolor variable is because this function modifies the content of the variable with an assignment statement on line any function can read the value of global variable without specifying the global statement if that function assigns value to global variable without global statementthen python considers that variable to be local variable that just happens to have the same name as global variable the main(function uses the bgcolor variable but doesn' need global statement for it because it only reads the contents of the bgcolor the main(function never assigns bgcolor new value this concept is explained in more detail at the game over animation def gameoveranimation(color=whiteanimationspeed= )