The recent Carpenter's Rule Theorem (2000) says that a polygonal linkage, made up of rigid bars connected into a chain, can always be folded into any possible configuration, while avoiding crossings between the bars and while preserving the bar lengths. We develop a new approach to folding such linkages based on following the gradient flow of a suitable energy function. This approach has several advantages over previous approaches in terms of mathematics, algorithms, and practice. On the mathematical side, we prove existence of a $C^\infty$ motion. On the algorithmic side, we give the first finite algorithm to construct an explicit piecewise-linear motion. On the practical side, our algorithm is straightforward to implement, possibly even physically without a computer.