They can change color when they want, as was already mentioned. When my erectus where mating they would change from black to white to yellow to green and red in the matter of a few minutes. I've heard diet has something to do with it also.
I do think some of the color can come from high nutrient water (ammonia, nitrite, nitrate, PO4, etc). We had some bright yellow young reidi in pristine water with daily large changes in the growout system (70+ gallons). When we put them in the display, which went through a small cycle because of their addition and feeding they changed from yellow to black. The water is back to normal now and most have said black and only flash white when a young male is trying to court.