Edit1; I just wanted to add something, in addition to protection, corals also use pigmentation to adjust the growth of Zooxanthellae. Basically pigments absorb the excess light at a certain wavelength (mostly bluer wavelengths as they are most useful for photosynthesis) and either radiate it back at another wavelength (this is called fluorescence) or the energy is dissipated as heat. Most common fluorescence is green color because the pigment absorbs every wavelength except for the wavelength that cannot also be absorbed by chlorophyll and either reflect it back or radiate it at greener wavelengths. We see organisms with chlorophyll green (such as plants) because chlorophyll cannot use green wavelengths and reflect it. That reflected wavelength comes to our eyes and we see them green. Coral use this to their advantage in a very smart way, they basically produce pigments that compete with chlorophyll and by adjusting the amount of these pigments, they can regulate the amount of light accessible to Zooxanthellae and accordingly their numbers.