The answer of how it is convert is the sun generates energy by slowly contracting in size; converting gravitational potential energy into thermal energy and this is called gravitational contraction. Gravitational collapse is the narrowing of an astronomical object due to the effect of its own gravity, which tends to draw matter inward toward the center of gravity.