Genes govern everything from the tiniest molecular interaction within a cell to the shape of the whole body and also the color of corn. Corn kernels have different colors because of genes that control color. Each kernel is an individual with its own set of genes, like an embryo.
Kernels are siblings housed on the same ear and so naturally have many different colors.
By naturally, I mean, through the course of natural selection. One-color ears are unnatural products of human selection. Livestock feeders prefer vitamin-rich yellow kernels, Southerners like white kernels, and Native Americans favor blue. Years of deliberate selection, careful pollination, and storing of seeds produced these single-color corn ears. In general, colors help a plant attract or repel other organisms or hide from predators.