Loop & bg problem

About that. What exactly is it that you want the program to do? Do you want to draw shapes while a key is being pressed, and then when the user stops pressing that key, do you want the screen to go blank, or do you want to display the last shape that was displayed before the keys stopped being pressed?

If you want the screen to just go blank, I recommend putting the polygon drawing sections in the same loop as the keyPressed statement.