Why do crystals, like quartz and diamonds, form in different colors?
The reason minerals like quarts and diamonds vary in color is generally caused by the chemical elements involved while the crystal is being formed.

Chemicals
Different colors can be created by different chemicals. Amethyst for example has traces of iron built into its crystalline structure giving it a purple hue. Iron can also give crystals a yellow hue.

[edit: See Gimelist's answer for a much more detailed and colorful explanation]



Growth Imperfections
Some colors, like in smoky quartz, are from growth imperfections. These imperfections change the way the crystal reflects light, which changes the appearance of coloration.



Light
Part of the color seen when looking at a crystal is light. When light enters a crystal its spectrum is broken apart, and part of it is absorbed while other parts are reflected. This changes the apparent color of the crystal.