Nature uses color in lots of different ways. In many animals, color camouflages the animal. In plants the opposite is more common -- color in flowers, for example, attracts insects to pollinate the flower. The purple color in red cabbage comes from a class of pigment molecules called anthocyanins. It turns out that anthocyanins are found in flower petals, leaves (it makes them turn red in the fall!) and some fruits such as blueberries. Anthocyanins are plant pigments known as flavenoids and produce red, pink, violet and magenta colors in the various plant parts.
The anthocyanidin group (See the sidebar below for the molecule structure) controls the color of the pigment. The electrons of the ring structures interact with incoming light and absorb various frequencies. (See How Light Works for a discussion of absorption.) The molecule shown below appears purplish red because its electrons absorb the yellow, green and blue portions of the visible spectrum.
One of the things that changes the color on anthocyanins is the level of acid or alkali (i.e., pH) around the molecule. Because the color of the anthocyanin is affected by the pH of the environment, these molecules can tell you the pH of any substance. If you make an extract of red cabbage juice, it will change color when mixed with solutions of various pH. The anthocyanin turns bright pink in acids, reddish-purple in neutral solutions and green in alkaline or basic solutions. This experiment shows you how to make a pH indicator from red cabbage!
Here are some interesting links: