Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Practical UI physics

Practical UI physics

Presented at Develop Denver 2015.

Watch the video on YouTube: https://www.youtube.com/watch?v=90oMnMFozEE
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.

David DeSandro

August 06, 2015
Tweet

More Decks by David DeSandro

Other Decks in Programming

Transcript

  1. Practical UI physics Change position with drag Keep moving after

    flick Flick movement slows Rubber band at ends
  2. function  update()  {      velocity  *=  friction    

     position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }
  3. function  update()  {      velocity  *=  friction    

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

         applyForce(  wind  )      velocity  *=  friction      position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }
  5. 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;   }
  6. //  calculate  resting  position   rest  =  position  +  

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

     position  +=  velocity   }   ! function  applyForce(  force  )  {      velocity  +=  force   }
  8. More resources Nature of Code (Ch. 1 & 2)
 natureofcode.com

    Coding Math
 youtube.com/user/codingmath