How are states of matter related to energy?