Algorithms for Animaon acvate Simple formulas to UI Courtney - - PowerPoint PPT Presentation

algorithms for anima on
SMART_READER_LITE
LIVE PREVIEW

Algorithms for Animaon acvate Simple formulas to UI Courtney - - PowerPoint PPT Presentation

Algorithms for Animaon acvate Simple formulas to UI Courtney Hemphill courtney @ carbonfive.com @chemphill #QConNewYork "You can take a problem that can't be solved directly by animaon and can't be solved by technology and work


slide-1
SLIDE 1

Algorithms for Animaon

Simple formulas to UI acvate

#QConNewYork Courtney Hemphill courtney@carbonfive.com @chemphill

slide-2
SLIDE 2
slide-3
SLIDE 3

"You can take a problem that can't be solved directly by animaon and can't be solved by technology and work together to acheive a much beer resoluon."

‐ Joe Longson, Senior Soware Engineer ‐ Zootopia

slide-4
SLIDE 4

 CLI   GUI   NUI

slide-5
SLIDE 5

Affordance & percieved affordance

slide-6
SLIDE 6

Animations are cognitive aids

slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9

Subtle Cues

slide-10
SLIDE 10
slide-11
SLIDE 11

Progressive Disclosure

slide-12
SLIDE 12
slide-13
SLIDE 13

Colin Garven hps:/ /dribbble.com/ColinGarven

slide-14
SLIDE 14

Auto Loading

slide-15
SLIDE 15

Navigation

slide-16
SLIDE 16

Adrian Zumbrunnen hp:/ /www.smashingmagazine.com/2013/10/23/smart‐transions‐in‐user‐experience‐design/

slide-17
SLIDE 17

Adrian Zumbrunnen hp:/ /www.smashingmagazine.com/2013/10/23/smart‐transions‐in‐user‐experience‐design/

slide-18
SLIDE 18

Context

slide-19
SLIDE 19

Jason Zigrino hps:/ /dribbble.com/shots/2749851‐Gboard‐Dark‐Material‐Moon

slide-20
SLIDE 20

Interactive

slide-21
SLIDE 21

Sergey Valiukh hps:/ /dribbble.com/SergeyValiukh

slide-22
SLIDE 22

How do you communicate animation ideas?

slide-23
SLIDE 23

Math

slide-24
SLIDE 24
slide-25
SLIDE 25

Motion

var ball = document.getElementById('ball'); var start = 0; var basicAnimation = function (e) { start += 12; basic.style.left = start + "px"; if (Math.abs(start) <= 800) { requestAnimationFrame(basicAnimation); } }

slide-26
SLIDE 26

The basics of animation: interpolation

valueAtTime = (end - start) * time / duration + start

slide-27
SLIDE 27

The basics of animation: interpolation

valueAtTime = (end - start) * time / duration + start

slide-28
SLIDE 28

Timing

(end - start) * time/duration + start div.style.left = 900-0 * time/1000 + 0+"px"

slide-29
SLIDE 29
slide-30
SLIDE 30

‐ Stanislaw Ulam "Using a term like nonlinear science is like referring to the bulk of zoology as the study of non‐elephant animals."

slide-31
SLIDE 31

Natural movement

Velocity, Acceleraon, Fricon, Torque

slide-32
SLIDE 32

Easing functions

slide-33
SLIDE 33

Easing

Change in property mes (some float) plus beginning value. (end - start) * easingfunction([0-1]) + start

slide-34
SLIDE 34

Power Functions - EaseIn

endX * Math.pow(percentChange, 3) + "px";

slide-35
SLIDE 35

Power Functions - EaseOut

(endX - startX)*(1 - Math.pow(1 - (t / d), 3)) +startX+"px";

slide-36
SLIDE 36

Trig! ... sine :)

(endX - startX)*Math.sin( t/d * Math.PI / 2 ) +startX+"px";

slide-37
SLIDE 37

Follow Through

> 1

slide-38
SLIDE 38

Elasticity

(endX - startX)*k * k * ( ( s + 1 ) * k - s ) +startX+"px";

slide-39
SLIDE 39

Bounce

if ( k < ( 1 / 2.75 ) ) { return 7.5625 * k * k; } else if ( k < ( 2 / 2.75 ) ) { return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; } else if ( k < ( 2.5 / 2.75 ) ) { return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; } else { return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; } }

slide-40
SLIDE 40

Physics Engines

slide-41
SLIDE 41
slide-42
SLIDE 42

Linear Interpolation Function (start, stop, amount)

function lerp(a,b,x) { return a+x*(b-a); }

slide-43
SLIDE 43

Radial motion

anim.theta += .02*Math.pow(1-anim.r/cw,8) * Math.PI; anim.p.x = anim.r * Math.cos(anim.theta); anim.p.y = anim.r * Math.sin(anim.theta);

slide-44
SLIDE 44

Depth (varying velocity)

// different shaped circles (depth) function shape() { return randomCircle(.006, .09) } // initializes each circle w/ random velocity (px/second) x:lerp(xmin,xmax,Math.random()), y:lerp(ymin,ymax,Math.random())} // basic equation: incremental x and/or y by velocity to get acceleration anim.p.x += anim.v.x anim.p.y += anim.v.y // this just keeps everything w/in the bounds of the canvas anim.p.x = (anim.p.x + cw/2) % cw - cw/2 anim.p.y = (anim.p.y + ch/2) % ch - ch/2

slide-45
SLIDE 45

Constraints (gravity)

// simple constraint of gradually increasing gravity gravity = lerp(0,2,fraction); // add an amount of gravity to the y velocity anim.v.y += gravity // same as before, add the velocity to the position anim.p.x += anim.v.x anim.p.y += anim.v.y // flip velocity for bounce anim.v.y = -.9*Math.abs(anim.v.y) // adds a bit of drag to slow down horizonal movement anim.v.x *= .99;

slide-46
SLIDE 46

Separation, Alignment, & Cohesion

// set boids direction towards center var centroidDirection = vsub(anim1.p, centroid) var centroidDistance = vlength(centroidDirection) // apply interaction force against boids var centroidForce = -attraction / (centroidDistance || .001) anim1.force.x += centroidForce * centroidDirection.x anim2.force.x += centroidForce * centroidDirection.x var rejectForce = rejection / (distance ? distance * distance : 0) anim1.force.x += rejectForce * direction.x anim2.force.x += rejectForce * direction.y // match velocity to nearby boids anim1.force.x += velocitySync * anim2.v.x anim2.force.x += velocitySync * anim1.v.x

slide-47
SLIDE 47

Collisions (engines!)

// create a world with a ground and some objects var bodyDef = new Box2D.Dynamics.b2BodyDef(); var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); // set the details for our constraints fixtureDef.density = 1.0; fixtureDef.friction = 0.5; // step through within constraints of our setup world.Step( 1 / 60 /* frame-rate */, 10 /* velocity iterations*/, 1 /* position iterations */);

slide-48
SLIDE 48

Static & Dynamic

// set body parts oriented in the right direction torso: partTransitions(0, -.04, .02, .04, -Math.PI/2), left_arm: partTransitions(-.018, -.03, .01, .03, -3*Math.PI/4), // sets how parts are attached to each other fixtureDef.filter.groupIndex = -1 // set up static & dynamic types addPhysics(anims.head[0], Box2D.Dynamics.b2Body.b2_staticBody, bodyDef, fixtureDef) groups.slice(1).forEach(function(group) { addPhysics(anims[group][0], Box2D.Dynamics.b2Body.b2_dynamicBody, bodyDef, fixtureDef) })

slide-49
SLIDE 49

Performance

slide-50
SLIDE 50

HTML, CSS, & JS Based

Use Keyframes, Transions & Transforms with CSS Use requestAnimaonFrame with JS Web Animaon API (WAAPI)

slide-51
SLIDE 51

RAIL

Response 100ms Animaon 6ms Idle 50ms Load 1000ms

credit Paul Irish & Paul Lewis and Blink T eam ( ) bit.ly/blink‐midnight‐train

slide-52
SLIDE 52

100 ms

slide-53
SLIDE 53

Rendering

Clear & Reuse Procedural Sprites Keep States Composing

slide-54
SLIDE 54
slide-55
SLIDE 55

The future is... meow

API WebVR Three.js Unity Unreal Engine A‐Frame

slide-56
SLIDE 56

Go play!

slide-57
SLIDE 57

References & Credits

Huge thanks to (@sivoh) Alex Cruikshank Don Norman ‐ The Design of Everyday Things Google Web Animaon Docs Box2dWeb

slide-58
SLIDE 58

Courtney Hemphill @chemphill courtney@carbonfive.com