It sure would be hard to explain to any young child why cooking would turn purple beans, such as the variety Royal Burgundy, from purple to green. Which cooking does. You can't respond by just saying, "Anthocyanins, my dear." You may have to wait a few years before offering a thorough answer.
A natural group of chemicals, called anthocyanins, are what put the purple in purple green beans, as well as in grapes, plums and, less familiar, purple broccoli. Anthocyanins are also what make roses and geraniums red, and cornflowers and delphiniums blue.
Not yellows and oranges, though; those colors come from carotenoids, which also are responsible for certain reds in plants. In the case of beets and bougainvilleas, the red comes from yet another natural pigment, called betacyanin.
A COLOR-CHANGING CHEMICAL
But back to anthocyanins. How can the very same anthocyanin — and there are a few different kinds — that makes one vegetable or flower red make another vegetable or flower blue?
Acidity of the cell sap is the key. The particular anthocyanin that is red in the very acidic sap of a rose petal is blue in the less acidic sap of a cornflower petal. Anthocyanins change color with changes in acidity, and eventually turn colorless as acid levels drop.
Two things happen during cooking to make Royal Burgundy beans turn from purple to green. A direct effect of the heat is to cause decomposition of anthocyanin. Less anthocyanin means less purple. The indirect effect of heat is to burst apart cells, diluting the acidity of the cell sap. The green color, which was present but masked by the anthocyanin, becomes prominent once the anthocyanin concentration drops, and what anthocyanin is still left becomes bathed in liquid insufficiently acidic to keep it purple.
A similar thing happens when you cook red cabbage. It turns colorless after awhile. You can also expect purple broccoli, purple asparagus, purple tomatillos, even purple peppers to lose their purple color after cooking. Red peppers stay red, though, because carotenoids give them their red color.
PURPLE HAS ITS PURPOSES
It may seem foolish to grow a purple vegetable if it is going to turn green anyway after you cook it. It's not as if that purple color does anything for flavor.
In nature, anthocyanins do have a purpose though, attracting insects to flowers and protecting plants from ultraviolet radiation, which is why you find purple in many alpine plants. Carrot shoulders exposed to sunlight sometimes even turn purple.
Actually, that purple in a vegetable does do us gardeners some good. The color can be very pretty in the vegetable garden. Also, because Royal Burgundy's foliage stays green, it is easier to pick out the purple pods from among the leaves. And perhaps birds can more easily spot and devour green cabbage worms on purple broccoli and red cabbage than on green varieties of either vegetable.
Furthermore, those purple beans do not really have to turn green before you eat them. You can eat green — or purple — beans raw, as many children, especially, often do. The way to prevent or lessen the color change of any cooked purple vegetable is to soak it before cooking in vinegar or lemon juice, increasing the acidity. Then minimize cooking. Because anthocyanins are tasteless, preserving the purple color will have no effect on flavor.