How a star is formed in space