David DeSandro
August 06, 2015
1.4k

# Practical UI physics

Presented at Develop Denver 2015.

Demos on CodePen: http://codepen.io/collection/XgYvmv/
Demos on GitHub: https://github.com/desandro/practical-ui-physics

Adding physics-based motion to UI can make digital interactions feel natural, comfortable, and delightful. So why is it so hard to get right, especially on the web? While mobile device SDK's have physics-based libraries built-in, web developers are missing a straight-forward way to add physics to their sites. This talk aims to solve that. Physics is a huge subject, and physics programming is often intimidating. But for UI developers, we need only to take advantage of its core principles in a practical model. This talk will cover the fundamentals of physics programming, how to develop your own physics model in JavaScript, and how to use that model to make UI feel natural.

August 06, 2015

## Transcript

9. ### Practical UI physics Change position with drag Keep moving after

ﬂick Flick movement slows Rubber band at ends

12. ### function  update()  {      velocity  *=  friction

position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }

16. ### function  update()  {      velocity  *=  friction

position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }
17. ### var  wind  //  particle  force   ! function  update()  {

applyForce(  wind  )      velocity  *=  friction      position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }

*  strength
20. ### var  attractionStrength  =  0.02;   ! function  update()  {

//  attract  particle  to  target      var  distance  =  target  -­‐  positionX;      var  attraction  =  distance  *         attractionStrength;      applyForce(  attraction  );   !    //  integrate  physics      velocity  *=  friction;      position  +=  velocity;   }

26. ### //  calculate  resting  position   rest  =  position  +

velocity  /  (  1  -­‐  friction  )
27. ### function  update()  {      velocity  *=  friction

position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }