In fluids, such as air, water, or molten rock, atoms and groups of atoms (molecules) move around freely in all directions at varying speeds. Atoms or molecules that are not electrically charged have little tendency to attach themselves to each other. Many, however, are charged, either positively or negatively. Those with opposite charges attract each other. If the charges are strong enough, they can serve to bind the particles to one another. For bonding to take place, the attraction has to be strong enough to overcome the particles' inertia (tendency of the moving particles to continue on their paths past one another).
If the particles are moving slowly enough and are close enough to each other, the forces of attraction may defeat inertia and the particles may attach (or bond) themselves to each other. When they do so, they form regular patterns.

One situation that causes atoms to slow down is falling temperature. As a gas or a liquid cools, the particles move more slowly and and may attach themselves to each other. In the diagram, bonds that tie atoms together are shown in blue.

A situation in which atoms are brought closer to one another is the evaporation of a solution. A solution (for example, salt water) consists of a 'solvent' (in this case water, shown in green), in which another substance, the 'solute' (in this case salt, whose constituent atoms are shown as red and white circles), is dissolved. As the solvent is removed, the atoms of the solute are brought into closer proximity, increasing the likelihood of collisions or near collisions that may result in their attaching themselves to one another. In the diagram, bonds that tie atoms together are shown in blue.
As atoms are drawn towards each other and attach (bond) themselves to each other, they arrange themselves in regular patterns. Substances whose atoms are arranged in such regular patterns are called 'crystalline' and the process is called 'crystallization'. When crystallization involving inorganic compounds occurs in nature, the result is a grain of the crystalline substance we call a mineral.
As more and more atoms arrive and bond to each other, the pattern keeps extending and the mineral grain grows.
Here several mineral grains are shown growing in a limited space, such as a hole in a rock. The hole is initially filled with a fluid from which mineral grains may form.
As the grains grow larger, they will begin to bump into one another.
Eventually, the hole may become completely filled. The mineral grains wrap around each other and interlock. The mineral grains have become attached and collectively they now form a rock.
Here is a picture of a granite with interlocking grains.

© 2001, David J. Leveson