Not all chameleons change colour in the way I think you are intending.
Whilst Panthers, Veileds and some of the other tropical tree-dwelling species can change to colours that include vivid blues, reds, yellows and greens, many species can only manage a change from dark to light colour.
Most leaf-litter dwelling chameleons have very limited colour changing ability - some don't change colour at all.
There are many theories as to why this is the case, and research is still being conducted on chameleons, but generally it seems to be related to the environment the chameleons live in.
The tropical tree-dwelling species seem to use colour changing more for communication than do other species, and this could be a reason for their wider palette of colours. There is a theory that vivid colours make it easier for chameleons to spot and identify one another in the dense forest canopies.
And leaf-litter dwelling chams, given their vulnerability on the ground, would probably never want to be spotted, hence they have developed more intricated leaf-like patterns on their skin, but have a reduced ability to change colours.
You should read
http://www.chameleonnews.com/colormechanism.html and
http://www.opticsforteens.org/everyday/nature/chameleon.asp for more information on the colour changing ability of chameleons.