Magma contains all of the chemicals and minerals of the Earth in hot and liquid form. When magma escapes from the heat and engages in cooling, rock forms. When the magma escapes into the atmosphere, it forms into "igneous extrusive" rock. When the magma remains confined and is not exposed to the atmosphere, it cools and hardens and is called "igneous intrusive" rock, or basalt.
The next step, cooling and hardening, determines what type of rock will be formed and how large the crystals form within the rock. In igneous extrusive rock, there are all of the changes that being in air, cooling rapidly, and being subject to the natural forces of nature cause. Chemical changes occur as gasses vent off. Water and air cools the rock quickly, sometimes so quickly that crystals cannot form at all, creating glassy forms of rock, such as obsidian. The disruptions of the Earth's crust, along with the venting of more magma can tumble, break, toss, wear down, and mix up the rock, in some cases melting it back into liquid so that it can cool and harden again.
Pressure from being under the weight of more rock can fuse rock together into various forms, from schists, which peel off in sheets, to metamorphic rocks, which are a packed together form of different types of rock, sometimes, embedded with larger crystals and other rocks and minerals.
Depending on the chemical elements and minerals that are in the magma, the rock will be formed in an amazing variety of ways. Igneous intrusive rock will take a lot more time to form, and crystals have the opportunity to grow to various sizes. Crystals maintain their shape and structure, whether they are too small for the eye to see or whether they grow to enormous size. There is the perfectly cubed form of salt, or the six sided form of quartz.
Veins of crystal can grow into the spaces and fractures that are available underground, then be broken and tumbled as the disruptions in the crust from water flow, glacial movement, meteor damage, lightning strikes, or other major natural events occur. Some events create instant results, others take millions of years.
Rocks that have been constantly exposed to water can be tumbled until they are rounded, or bashed and broken until they are in the form of grains of sand, or farther into soil and silt, which can then be packed together under enormous pressure to create even more fabulous new forms.