Fabric simulation in Processing. It uses verlet integration. I did my best to comment the code.
I wrote a tutorial on how the algorithm works: http://bluethen.com/wordpress/index.php/processing-app/curtain/ and a follow-up to that tutorial here (this one describes how to use a consistent timestep, among other things): http://bluethen.com/wordpress/index.php/processing-app/updated-cloth-simulator-and-how-to-improve-your-verlet-cloth-simulator/
Left click and drag to interact. Right click to tear. Press 'G' to toggle gravity. Press 'R' to reset.