The rock deformation and failure characteristics and mechanisms are very important for stability evaluation and hazard control in rock engineering. The process of rock deformation and failure is often accompanied by temperature changes. It is of great significance to study the characteristics and mechanism of temperature variation in rock under deformation and fracturing for a better understanding of rock failure and to obtain some probable precursor information for guiding the prediction of the mechanical behavior of rock. However, most of the studies are based on observations in the field and laboratory tests, while it is still required to develop an effective method for modeling and calculating the temperature variation of rock during the deformation and failure processes. In this paper, a particle flow modeling method based on energy analyses is proposed for simulating the temperature variation of rocks, considering four temperature effects, including the thermoelastic effect, friction effect, damping effect, and heat conduction effect. The four effects are analyzed, and the theoretical equations have been provided. On this basis, the numerical model is built and calibrated according to the laboratory uniaxial compressive experiment on a marble specimen, and a comparison study has been conducted between the laboratory and numerical experiment results. It is found that the numerical model can well simulate the average value and distribution of the temperature variation of rock specimens, so this method can be applied for studying the mechanism of temperature variation more comprehensively during the whole process of rock deformation and fracturing compared with the continuous modeling methods. With this method, it is shown that the temperature change has three different stages with different characteristics during the uniaxial compression experiments. In the different stages, the different effects play different roles in temperature variation, and stress distribution and crack propagation have obvious influences on the local distribution of temperature. Further investigations have also been conducted in a series of sensitive analyses on the influences of four factors, including the thermal conductivity, friction coefficient, thermal expansion coefficient, and particle size ratio. The results show that they have different influences on the thermal and mechanical behaviors of the rock specimens during the deformation and failure process, while the thermal expansion coefficient and the particle size ratio have more significant impacts than the other two factors. These findings increase our knowledge on the characteristics and mechanism of temperature variation in rock during the deformation and fracturing process, and the proposed modeling method can be used in more studies for deformation and fracturing analyses in rock experiments and engineering.