Diamond and graphite are both composed solely of carbon. Why are they so different? Geometry.
Start by considering methane, a molecule of natural gas that has one central carbon, and four peripheral hydrogens. No hydrogen is preferred over the others, so they settle in a very symmetrical configuration called a tetrahedron. Each bond is identical, and the angle between each pair of bonds is (approximately) 109.5°. It is highly saturated (lots of hydrogen per carbon) and so is a good source of energy.
Next, imagine that each hydrogen atom is instead itself another carbon. Can you make a crystal by extending this pattern indefinitely? Yes! In diamond, every carbon atom is bonded to four carbon neighbors, in a tetrahedral pattern. Each bond is identical, and the angle between each pair of bonds is that same 109.5°. This uniformity makes the diamond crystal very strong and stable.
The three neighbors of the central (blue) carbon are colored bright red. The explanation of the other red carbons follows.
In the diamond lattice, which is based on this tetrahedral pattern, there is nonetheless a recurring cubic pattern. The red atoms, taken together, form the vertices of a cube.
The next page shows the structure of graphite, which in contrast to diamond, is opaque and soft.