The two major sources of energy for the rock cycle are the sun, which provides energy for surface processes such as weathering, erosion, and transport, and the Earth's internal heat provides energy for processes like subduction, melting, and metamorphism. And Magma, when it is allowed to cool, it crystallizes, much the same way that ice crystals develop when water is cooled. We see this process occurring in places like Iceland, where magma erupts out of a volcano and cools on the surface of the Earth, forming a rock called basalt on the flanks of the volcano
----------------------------------------
how each source of energy causes the rock to change forms:
Over many thousands of years, energy from the Sun moves the wind and water at the Earth’s surface with enough force to break rocks apart into sand and other types of sediment. When sediment is buried and cemented together, it becomes a sedimentary rock such as sandstone or shale.
Magma is a hot liquid made of melted minerals. The minerals can form crystals when they cool. Igneous rock can form underground, where the magma cools slowly. Or, igneous rock can form above ground, where the magma cools quickly.