Either the Graphics Card is going bad, or the capacitors on the logic board are going bad.
If you have a non-iSight G5, you can easily remove the back of the computer, and see if the capacitors are bulging, or leaking, or if there are dark spots on the top of them.
I have/had a simliar problem with my G5 ALS, and my graphics card is the problem.
If it's the capacitors, they can be replaced by a good technician, costs between $250-$350 dollars.
Google 'iMac G5 capacitor replacement'.