There are two groups of lizards commonly called chameleons, and they change colors in different ways.
True chameleons belong to an Old World family called Chamaeleontidae, with two genuses and about eight-five species.
They have a variety of colorations, which they can change, to a greater or lesser extent, by concentrating or spreading out the pigmentation in skin cells, called melanophores.
The process is under the control of the autonomic nervous system, and the change is not just a matter of color matching. Rather, it is a complex response to a variety of conditions, including light and temperature, but also “emotional” factors such as fear or triumph in battle with another chameleon.
The strength of the light is apparently the most important factor, and for certain species, this sometimes results in camouflage.
For example, the flap-necked chameleon, Chanuteleo dilepis, an African species, turns green when among leaves and yellow or reddish-brown when on bark. However, in response to a threat, it turns blackish-green, with yellow and white spots.
Members of the other group sometimes called chameleons, anoles (which are New World relatives of the iguana in the genus Anolis), have a limited color-change system under the control of hormones rather than nerves.