Code Monkey home page Code Monkey logo

popmotion's Introduction

Popmotion

The animator's toolbox

npm version npm downloads Twitter Follow

Popmotion is:

  • Powerful: It supports keyframe and spring animations for numbers, colors and complex strings.
  • Low level: It's designed to be composable and portable into any JavaScript environment, with an eye on worklets in the future.
  • Stable: It's written in TypeScript and enjoys over 95% test coverage.
  • Tiny: animate is just ~4.5kb, and every function is individually importable.

Quick start

npm install popmotion
import { animate } from "popmotion"

animate({
  from: 0,
  to: 100,
  onUpdate: latest => console.log(latest)
})

Animation

animate

animate performs a keyframes or spring animation.

import { animate } from "popmotion"

animate({
  from: 0, 
  to: 100,
  onUpdate: latest => console.log(latest)
})

It can animate numbers:

animate({ from: 0, to: 100 })

Or strings of the same type:

animate({ from: "0px", to: "100px" })
animate({ from: "#fff", to: "#000" })

The strings can be pretty complex, for instance box shadows or SVG path definitions. The only limitation is that the numbers and colors contained within must be in the same order:

animate({
  from: "0px 0px 0px rgba(0, 0, 0, 0)",
  to: "10px 10px 0px rgba(0, 0, 0, 0.2)"
})

The type of animation performed will be automatically detected from the provided options, or can be chosen manually by defining type as "keyframes", "spring" or "decay".

Options

These options can be set for all animations:

from

An initial value to start the animation from.

Defaults to 0

animate({
  from: "linear-gradient(#e66465, #9198e5)",
  to: "linear-gradient(#9198e5, #e66465)"
})
elapsed

Sets an initial elapsed time, in milliseconds. Set to a negative value for a delay.

animate({
  to: 100,
  elapsed: -300
})
repeat

The number of times to repeat the animation. Set to Infinity to repeat forever.

animate({
  to: 100,
  repeat: 2
})
repeatDelay

The duration, in milliseconds, to wait before repeating the animation.

animate({
  to: 100,
  repeat: 2,
  repeatDelay: 200
})
repeatType

Either "loop", "mirror" or "reverse". Defaults to "loop".

  • "loop": Repeats the animation from 0.
  • "mirror": Swaps the from/to values alternately.
  • "reverse": Reverses the animation alternately.
animate({
  to: 100,
  repeat: 2,
  repeatType: "reverse"
})
driver

By default, the animation will be driven by a requestAnimationFrame loop. driver can specify a different source.

A Driver is a function that accepts the animations update function. This is a function that can be called with a time delta from the previous frame. The Driver must return a function that will be called when the animation is stopped.

const xrDriver = session => update => {
  let latestRequestId = 0
  let prevTimestamp = performance.now()
  
  const step = timestamp => {
    const delta = timestamp - prevTimestamp
    prevTimestamp = timestamp

    update(delta)

    latestRequestId = session.requestAnimationFrame(step)
  }

  let latestRequestId = session.requestAnimationFrame(step)

  return () => session.cancelRequestAnimationFrame(latestRequestId)
}

animate({
  to: 100,
  driver: xrDriver(xrSession)
})
type

animate will automatically detect the type of animation to use based on the options provided. But a specific type can be chosen manually by defining type as "keyframes", "spring" or "decay".

animate({
  to: 100,
  type: "spring"
})

Lifecycle events

The following lifecycle events are available for all animations:

onUpdate

This is called every frame the animation fires with the latest computed value.

animate({
  to: 100,
  onUpdate: latest => console.log(latest)
})
onPlay

This is called when the animation starts. Currently this automatically when animate is called.

animate({
  to: 100,
  onPlay: () => {}
})
onComplete

This is called when the animation successfully completes.

animate({
  to: 100,
  onComplete:() => {}
})
onRepeat

This is called when an animation repeats.

animate({
  to: 100,
  repeat: 2,
  onRepeat: () => {}
})
onStop

This is called when the animation is stopped by the stop control.

const animation = animate({
  to: 100,
  onStop: () => {}
})

animation.stop()

Keyframes options

A keyframes animation is the default animation type and it can be defined either with a from and to option:

animate({ from: 0, to: 100 })

Or as a series of keyframes provided to the to option:

animate({ to: [0, 100, 200] })
to

A single value to animate to, or an array of values to animate through.

animate({
  to: ["#0ff", "#f00", "#0f0"]
})

If to is an array, any defined from will be ignored.

duration

This defines the duration of the animation, in milliseconds.

animate({
  to: 100,
  duration: 300
})
ease

This is an easing function, or array of functions, to use when easing between each keyframe.

import { animate, linear, easeInOut } from "popmotion"

animate({
  to: 100,
  ease: linear
})

animate({
  to: ["#fff", "#000", "#f00"],
  ease: [linear, easeInOut]
})

If set as any array, the length of this array must be one shorter than the number of values being animated between.

offset

This is an array of values between 0 and 1 that defines at which point throughout the animation each keyframe should be reached.

This array should be the same length as the number of defined keyframes.

animate({
  to: ["#fff", "#000", "#f00"],
  offset: [0, 0.2, 1]
})

Spring options

Springs are great for creating natural-feeling interfaces and dynamic interruptable animations.

A spring animation will be used if any of the stiffness, damping or mass options are detected.

Note: A spring simulation is inherently numerical so if it's given a color, array or object, it runs the animation from 0 to 100 and interpolates that to the given values. This strategy is likely to be tweaked before the official release so animations made this way may change in feel.

to

A single value to animate to.

animate({
  to: 100,
  type: "spring"
})

If to is an array, any defined from will be ignored.

stiffness

This defines the stiffness of the spring. A higher stiffness will result in a snappier animation.

Defaults to 100

animate({
  to: 100,
  stiffness: 1000
})
damping

This is the opposing force to stiffness. As you reduce this value, relative to stiffness, the spring will become bouncier and the animation will last longer. Likewise, higher relative values will have less bounciness and result in shorter animations.

Defaults to 10

animate({
  to: 100,
  damping: 50
})
mass

This is the mass of the animating object. Heavier objects will take longer to speed up and slow down.

Defaults to 1.

animate({
  to: 100,
  mass: 2
})
velocity

The initial velocity, in units per second, of the animation.

animate({
  to: 100,
  velocity: 1000
})
duration

The duration of the spring, in milliseconds.

Will be overridden by stiffness, mass or damping.

animate({
  to: 100,
  duration: 1000
})
bounce

The bounciness of the spring, as a value between 0 and 1, where 0 is no bounce.

Will be overridden by stiffness, mass or damping.

animate({
  to: 100,
  bounce: 0.2
})
restDelta

The distance from the animation target at which the animation can be considered complete. When both restDelta and restSpeed are met, the animation completes.

animate({
  to: 100,
  restDelta: 0.5
})
restSpeed

The absolute velocity, in units per second, below which the animation can be considered complete. When both restDelta and restSpeed are met, the animation completes. Defaults to 10.

animate({
  to: 100,
  restSpeed: 5
})

Playback controls

animate returns PlaybackControls, which can be used to control the playback of the animation.

Currently this only includes a stop method, but may expand with more.

stop

Stops the animation.

const playback = animate({ from: 0, to: 100 })
playback.stop()

inertia

The inertia animation is used to gradually decelerate a number. Think smartphone scroll momentum.

Options

In addition to animate's from, onUpdate and onComplete options, inertia also supports the following:

velocity

The initial velocity, in units per second, of the animation.

inertia({
  from: 0,
  velocity: 100
})
power

A constant with which to calculate a target value. Higher power = further target.

Defaults to 0.8.

inertia({
  from: 0,
  power: 0.3
})
timeConstant

Adjusting the time constant will change the duration of the deceleration, thereby affecting its feel.

Defaults to 350.

inertia({
  from: 0,
  velocity: 100,
  timeConstant: 400
})
modifyTarget

A function that receives the calculated target and returns a new one. Useful for snapping the target to a grid.

const roundToNearest = target => v => Math.ceil(v / target) * target

inertia({
  from: 0,
  velocity: 100,
  modifyTarget: roundToNearest(100)
})
min

The minimum value at which the animation will switch from gradual deceleration and use a spring animation to snap to this point.

inertia({
  from: 50,
  velocity: -100,
  min: 0
})
max

The maximum value at which the animation will switch from gradual deceleration and use a spring animation to snap to this point.

inertia({
  from: 50,
  velocity: 100,
  max: 100
})
bounceStiffness

This defines the stiffness of the spring when the animation hits either min or max. A higher stiffness will result in a snappier animation.

Defaults to 500

inertia({
  from: 0,
  velocity: 100,
  max: 50,
  bounceStiffness: 1000
})
bounceDamping

This is the opposing force to bounceStiffness. As you reduce this value, relative to bounceStiffness, the spring will become bouncier and the animation will last longer. Likewise, higher relative values will have less bounciness and result in shorter animations.

Defaults to 10

inertia({
  from: 0,
  velocity: 100,
  max: 50,
  bounceDamping: 300
})
restDelta

The distance from the animation target at which the animation can be considered complete.

inertia({
  from: 0,
  velocity: 100,
  restDelta: 0.5
})

Iterators

Powering animate and inertia are the keyframes, spring, and decay iterators.

import { keyframes, spring, decay } from "popmotion";

Iterators give you the ability to run an animation with a high degree of control. For example, Framer uses the spring iterator to draw its animation editor visualiser by running it synchronously.

Each can be initialised with the matching options above (decay with a subset of inertia's options, excluding the bounce- options):

const animation = spring({
  from: 0,
  to: 100,
  stiffness: 200
})

With the returned iterator, you can resolve the animation at a specific timestamp with its next method.

// Resolve the animation at 200ms
const { value, done } = animation.next(200)

Easing

Popmotion includes a number of in-built easing functions, as well as factory functions to make entirely new ones.

Functions

Each easing function can be imported like so:

import { linear } from "popmotion"

Each function accepts a progress value between 0 and 1, and returns a new one:

const progress = 0.5
const easedProgress = easeInOut(progress)
  • linear
  • easeIn
  • easeInOut
  • easeOut
  • circIn
  • circInOut
  • circOut
  • backIn
  • backInOut
  • backOut
  • anticipate
  • bounceIn
  • bounceInOut
  • bounceOut

Factories

cubicBezier

import { cubicBezier } from "popmotion"

const easing = cubicBezier(0, .42, 0, 1)

New cubic bezier definitions can be created in the Framer animation editor and copy/pasted directly into this function.

steps

steps returns an easing function that will convert the animation into a discrete series of steps.

import { steps } from "popmotion"

const easing = steps(5)

It optionally accepts a second parameter, either "start" or "end" (default)that decides whether the steps are aligned with the start or end of the animation.

steps(5, "start")

mirrorEasing

Mirrors an existing easing function.

reverseEasing

Reverses an existing easing function. For instance, providing it easeIn would return an easeOut.

import { reverseEasing, linear } from "popmotion"

const reversed = reverseEasing(linear)
reversed(1) // 0
reversed(0.5) // 0.5
reversed(0) // 1

createExpoIn

Creates an easing function based on the exponent of the provided power. The higher the power, the stronger the easing.

import { createExpoIn } from "popmotion"

const expoIn = createExpoIn(4)

The returned easing function is an ease in, which means it starts slow and finished fast. mirrorEasing and reverseEasing can be used to create ease in out, and ease out variations:

const expoIn = createExpoIn(4)
const expoOut = mirrorEasing(easeIn)
const expoInOut = reverseEasing(easeIn)

createBackIn

Creates an easing function with an overshoot. It accepts a power value, the higher the power the stronger the overshoot.

import { createBackIn } from "popmotion"

const backIn = createBackIn(4)

The returned easing function is an ease in, which means the overshoot happens at the start of the animation. mirrorEasing and reverseEasing can be used to create ease in out, and ease out variations:

const backIn = createBackIn(4)
const backOut = mirrorEasing(easeIn)
const backInOut = reverseEasing(easeIn)

createAnticipate

Creates an easing that pulls back a little before animating out with an overshoot. The stronger the power the bigger the overshoot.

import { createAnticipate } from "popmotion"

const anticipate = createAnticipate(4)

Utils

angle

Returns an angle between two points, in degrees.

import { angle } from "popmotion"

angle(
  { x: 0, y: 0 },
  { x: 45, y: 100 }
)

attract

import { attract } from "popmotion"

attract(5, 10, 12)

attractExpo

import { attractExpo } from "popmotion"

attractExpo(5, 10, 12)

clamp

Clamp a value to within the given range.

import { clamp } from "popmotion"

const min = 50
const max = 100
clamp(min, max, 150) // 100

degreesToRadians

Converts degrees to radians.

import { degreesToRadians } from "popmotion"

degreesToRadians(45) // 0.785...

distance

Returns the distance between two numbers, two 2D points, or two 3D points.

import { distance } from "popmotion"

distance(10, 50)
distance({ x: 0, y: 0 }, { x: 45, y: 100 })
distance({ x: 0, y: 0, z: 100 }, { x: 45, y: 100, z: 0 })

interpolate

Creates a function that will interpolate from an linear series of numbers, to a non-linear series of numbers, strings of the same numerical format, colours, or arrays/objects of those.

import { interpolate } from "popmotion"

const mapXToOpacity = interpolate(
  [-100, 0, 100],
  [0, 1, 0]
)
mapXToOpacity(-50) // 0.5

const mapProgressToValues = interpolate(
  [0, 1],
  [
    { x: 0, color: "#fff" },
    { x: 100, color: "#000" }
  ]
)
mapProgressToValues(0.5) // { x: 50, color: "#888" }

const rescale = interpolate(
  [0, 1],
  [100, 200],
  { clamp: false }
)
rescale(2) // 300

Options

interpolate accepts an optional third argument, an object of options.

  • clamp: Clamps values to within given range. Defaults to true.
  • ease: An Easing function, or array of easing functions, to ease the interpolation of each segment.
  • mixer: A function that, when provided a from and to value, will return a new function that accepts a progress value between 0 and 1 to mix between those two values. For integration with libraries like Flubber.

isPoint

Returns true if the provided argument is a 2D point.

import { isPoint } from "popmotion"

isPoint({ x: 0 }) // false
isPoint({ x: 0, y: 0 }) // true

isPoint3D

Returns true if the provided argument is a 3D point.

import { isPoint3D } from "popmotion"

isPoint3D({ x: 0 }) // false
isPoint3D({ x: 0, y: 0 }) // false
isPoint3D({ x: 0, y: 0, z: 0 }) // true

mix

Will mix between two values, given progress as a third argument.

import { mix } from "popmotion"

mix(0, 100, 0.5) // 50
mix(0, 100, 2) // 200

mixColor

Returns a function that, when provided a progress value, will mix between two colors. Accepts hex, rgba and hsla colors.

import { mixColor } from "popmotion"

mixColor("#000", "#fff")(0.5) // "rgba(125, 125, 125, 1)"

mixComplex

Returns a function that, when provided a progress value, will mix between two strings with the same order of numbers and colors.

import { mixComplex } from "popmotion"

mixComplex("100px #fff", "0px #000")(0.5) // "50px rgba(125, 125, 125, 1)"

pointFromVector

Given a point, angle in degrees, and distance, will return a new point.

import { pointFromVector } from "popmotion"

const point = { x: 0, y: 0 }
const angle = 45
const distance = 100

pointFromVector(point, angle, distance)

progress

Given a min and a max range, and a value, will return the progress of the value within the range as normalised to a 0-1 range.

import { progress } from "popmotion"

const min = 100
const max = 200
progress(min, max, 150) // 0.5

radiansToDegrees

Converts radians to degrees.

import { radiansToDegrees } from "popmotion"

radiansToDegrees(0.785) // 45

snap

Creates a function that will snap numbers to the nearest in a provided array or to a regular interval.

import { snap } from "popmotion"

// Snap to regular intervals
const snapTo = snap(45);

snapTo(1); // 0
snapTo(40); // 45
snapTo(50); // 45
snapTo(80); // 90

// Snap to values in an array
const snapTo = snap([-100, -50, 100, 200]);

snapTo(-200); // -100
snapTo(-76); // -100
snapTo(-74); // -50

toDecimal

Rounds a number to a specific decimal place.

import { toDecimal } from "popmotion"

toDecimal(3.3333); // 3.33
toDecimal(6.6666, 1); // 6.67

velocityPerFrame

import { velocityPerFrame } from "popmotion"

velocityPerFrame(50, 16.7); // 0.835

velocityPerSecond

import { velocityPerSecond } from "popmotion"

velocityPerSecond(1, 16.7); // 59.880...

wrap

import { wrap } from "popmotion"

wrap(0, 1, 0.5); // 0.5
wrap(0, 1, 1.5); // 0.5

popmotion's People

Contributors

alirezavalizade avatar andarist avatar brunnolou avatar dbismut avatar dd1994 avatar dschu-lab avatar efimweb avatar emiltholin avatar jamieowen avatar jesstelford avatar klaasman avatar littlemilkstudio avatar mars avatar mattgperry avatar mattperry8 avatar mrdoob avatar mxstbr avatar naskapal avatar oori avatar philipdavis avatar pleunv avatar rossng avatar snowyu avatar spruce-bruce avatar stoikerty avatar stokesman avatar strax avatar tbroadley avatar terrierscript avatar voxpelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

popmotion's Issues

Timeline feature

thanks for this project. Is there a timeline plugin to control multiple animations?

About setting initial values

Hi Matt, I have this fork based on your pen "circle movement..." ( http://codepen.io/tinchox5/pen/KVKZXq)
I wanted to set initial position of "box" actor, so I thought that setting initial properties were enough to do that. But this didn't work for me, so I had to create a "fake tween":

var circularMovement0 = new ui.Tween({
duration: 0
});

Doing that it worked,but I think this isn't the correct way.

What is the real size of the lib?

The repository description says:
A 14kb Javascript motion engine. Use for animation, physics and input tracking.

The readme says:
Popmotion is a 12kb JavaScript motion engine. Use it for for animation, physics, and input tracking. In the browser, on Node, anywhere.

And the downloaded file have: 39.145 bytes (41 KB on disk)

I think is good to unify this and also clarify if this size is when gziped and minified.

Doesn't work in IE9 as advertised

Hey Matt,

nice job with this project, looks very promising! The narrow focus makes it useable for React which is exactly what I was looking for (a physics engine that I can incorporate into state) :)

Now onto business... I hate to be the guy pointing this out. You advertise popmotion as being compatible with IE9. Your main site popmotion.io throws this error:

SCRIPT438: Object doesn't support property or method 'now' 
site.js, line 1257 character 2

I haven't looked into it in depth, it feels like this might have to do with how performance.now is implemented.

Is it possible to force css role to svg element?

Hi Matt @InventingWithMonster , I have this codepen http://codepen.io/tinchox5/pen/WQZLQG in which I try to use the css benefits in order to override some svg limitations (ej rotateX, rotateY). I tried to force css role when I set Actor,but that didn't work. So, I wrote some css rules using onComplete but this is not the idea. I mean it would be nice to set css values directly in Tween.
Have you got any suggestion?
Thanks

BUG: Bezier numbers not rounded correctly

Numbers eased with BezierCurve aren't rounded correctly. For instance a number intended to end at 1 will end at 0.9987xxxxxxx

Actions:

  1. Round numbers to three decimal places (for yums)
  2. Investigate Bezier easing and hard set numbers at 1 to .to if fix isn't possible.

Simulate transform

Hi, hope you dont mind me asking here.

I am trying to simulate the transform: scale from 0 to 1 with a spring movement.
Similar to this:
http://codepen.io/popmotion/pen/dogNpp

Here is a pen showing you the version i have modified.
http://codepen.io/anon/pen/VeZvqR

Unfortunately the results are somewhat different each turn.
Is there a way to apply a duration to simulate?

Awesome library by the way. (Will definitely buy when you have collision detection) :)

Latest version unavailable through Bower

I use npm for package management when I can, but I work on many projects that exclusively use Bower for front-end packages.

It's impossible to use the current version of Popmotion through Bower because a few things are missing:

  • The bower.json file needs a "version": "3.1.3", so Bower can find the latest version
  • The project needs a git tag of 3.1.3 added so Bower knows where to find the latest version.
  • The main in bower.json is currently pointing to the wrong place. It should probably be "main": "popmotion.global.js" so various front-end tooling setups know where to find the main .js file.

If you add the 3.1.3 git tag I'm happy to create a PR for the rest. What do you think?

strange behavior with opacity 0

Matt, I have this pen http://codepen.io/tinchox5/pen/YwPREE

I defined some tweens, one is called fadeIn and another fadeOut. FadeIn (opacity:1) works perfect, but fadeOut (opacity:0) isn't working when I use toggle().reverse() . I mean the opacity style doesnt change when I monitoring via browser inspector tool (chrome).

You can see the problem touching the circle situated at the top left main circle.

Is it a kind of bug or my fault?

Please add SVG morphing to the popmotion features

Please add SVG morphing to the popmotion features. I'm referring to something like the Greensock morphSVGPlugin:

Video: https://www.youtube.com/watch?v=Uxa9sdaeyKM
LIve Demo: http://codepen.io/cjgammon/pen/EVWjBO/

You can morph any shape into another (and you don't have to maintain same number of points between the start and the destination shape). Inbetweens for cartoon animations will be automatically generated from a small number of keyframes created in Inkscape or Illustrator, for example.
Greensock tweenmax is bloated compared to popmotion, and I would prefer using popmotion for SVG morphing.

watch x

The get started say :

var foo = new ui.Track({
    values: {
        x: {}
        // equivalent to
        // x: { watch: 'x' }
    }
});

but

var foo = new ui.Track({
    values: {
        x: { watch: 'x' }
    }
});

doesn't work :)

rotateZ simulation animates invalid values

This could be a bug and it could just be a misunderstanding of pop motion on my part.

I've put together a simple test case to demonstrate the issue here: http://codepen.io/cmalven/pen/dYvevW?editors=001

When the rectangle is dragged, I'm using a track to apply the x value to rotateZ, then using a simulation to spring back the rotateZ when the mouse is released.

The x-based rotation on drag works fine, but when I release the mouse button the rotateZ value just snaps back into place without applying the spring simulation.

Examining the rotateZ values generated during the simulation suggest why this might not be working: they quickly become invalid values like rotateZ: "-7.450580596923828e-7deg"

Any ideas?

Tween seems to reset

After the first tween, a second tween seems to start from the original position instead of the end result of the first tween. Is this intentional? Is there a way to specify from/to values for a tween?

Using Redshift isomorphically.

Hi Matt, Thanks for telling about the svg path route fix. Before checking on that, right now I'm trying to integrate Redshift wir Cycle.js (which is using virtual-dom itself) -> https://github.com/staltz/cycle.

The goal is to get an implemenation based on the isomorphic Cycle example -> https://github.com/staltz/cycle/tree/master/examples/isomorphic

Isomorphic here just means the app can render both, from the client and the server.

As Redshift is coupled with the window object because of the dom, it throws an error server side and I wonder, if there is a way to entirely decouple Redshift from the Dom so Redshift could be used also as a NPM module with isomorphic abilities?

Possible bug?

Matt, in this working pen http://codepen.io/tinchox5/pen/eJYLMM I defined an Actor (new ui.Actor),then I set some properties (.set), and finally I put .sync(), like this:

var box = new ui.Actor({
element: '.box'
});
box.set({
values: {
originX: 0,
originY: 0,
distance: 180,
angle: 240,
opacity: 1,
x: {
transform: fromAngleAndDistance
},
y: {
transform: fromAngleAndDistance
}
}
}).sync();

I wanted to simplify some lines of code, so I did it this:
var box = new ui.Actor({
element: '.box',
values: {
originX: 0,
originY: 0,
distance: 180,
angle: 240,
opacity: 1,
x: {
transform: fromAngleAndDistance
},
y: {
transform: fromAngleAndDistance
}
}
}).sync();

The code isn't working anymore and Console shows : "Uncaught RangeError: Maximum call stack size exceeded"

Here is the new pen http://codepen.io/tinchox5/pen/eJYqaj

Need a basic Meteor package

Wrap the library for use in Meteor.
So folk can use popmotion with meteor using meteor add london:popmotion

Can't get 'watch' to work

Hi there,

I really like what you've been doing with Popmotion!
So far it's been a breeze to work with, just one thing: I can't get the watch-property to work.

What are some potential reasons? As far as I can see I am doing everything as specified.

var handle = new ui.Actor({
    element: '.' + styles.testObject,
    values: {
        iris: {
            watch: 'x'
        }
    },
    onUpdate: function (output){
        console.log(output.iris)
    }
})

var horizontal = new ui.Track({
    values: {
        x: {}
    }
})

The x value is output correctly, but the iris just stays 0, no matter what I do.
In case that might be relevant, I am using React.

Perhaps you have an idea?

Thanks a bunch,
— Maxi

Lag on mobile

I've been trying to use your library for its gravity component and it works pretty well, the only issue is that it lags on mobile devices, especially the iPhone 4 and iPad. What can I do to avoid this?

Website and pricing questions

Hi Matt, I'm bit confused. I know for twitter that popmotion 4 has already released, but in the website an older version is shown. Another thing that confused me is what happened with the price of popmotion. Is it free or not? is there a way to donate in order to support the development?
Thank you,
Martin

[Question] How to apply Sequence when you have defined Controls

Hi Matt, I´m a bit stuck traying to implement Sequence in order to optimice my animation. The main problem is that I need to set Controls because of mouse events. I mean, when I click on Search Circle, the animation starts,then when I click again I have to reverse animation based on the previuos controls.
PEN. http://codepen.io/tinchox5/pen/YwPREE

The straight forward is :
(Line 142 )
//interaction
$('.search').one('mousedown', function(e) {
var ctrlpag = paginator.start(fadeOutPag);
var ctrlsearch = search.start(circularMovement);
var ctrlc2 = circle2.start(circular2);
var ctrlcircle = circle.start(fadeIn);
var ctrlcontact = contact.start(fadeOut);
var ctrlsb = searchBox.start(enlarge);

$('.search').on('mousedown', function(e) {
ctrlpag.toggle().reverse();
ctrlsearch.toggle().reverse();
ctrlc2.toggle().reverse();
ctrlcircle.toggle().reverse();
ctrlcontact.toggle().reverse();
ctrlsb.toggle().reverse();

});
});

The problem is that all animations starts at same time, so many lags occurs on mobile. Also, I can´t set "delays" into tween because I need to reverse them later.

For this reason, I tried to implement Sequence in this way:

//interaction
$('.search').one('mousedown', function(e) {
var sequence = new ui.Sequence();
sequence
.do(function(){
var ctrlpag = paginator.start(fadeOutPag);
}).then(function(){
var ctrlsearch = search.start(circularMovement);
}).then(function(){
var ctrlc2 = circle2.start(circular2);
}).then(function(){
var ctrlcircle = circle.start(fadeIn);
}).then(function(){
var ctrlcontact = contact.start(fadeOut);
}).then(function(){
var ctrlsb = searchBox.start(enlarge);
});

$('.search').on('mousedown', function(e) {
<--omitted code-->
});
});

But console shows that ---> "TypeError: e.split is not a function"

Maybe I´m not clear but have you got any suggestion to implement Sequence when Controls are also defined?

new Actor

Just found that this work :

new ui.Actor('.class-example');

and :

new ui.Actor(document.getElementsByClassName('class-example')[0]);

does not work :) is it normal ? because according to http://popmotion.io/api/actor it should work with both DOM selectors & DOM elements

Change values to track dynamically

Is it possible to change values to track dynamically (just in motion)? For example: initially I'd like to track only y but as soon as y === 20px I'd like to track x as well.

License

Am I correct in saying that Popmotion is no longer open source as it restricted to non commercial projects only?

I was using Popmotion in a library which I'll be releasing now but how am I supposed to be able to release that under a non restrictive license when Popmotion cannot be used in commercial environments? I'm going to have to look for alternatives or continue to use an older version which uses MIT.

Popmotion watch / scrubber example.

Using popmotion.global.min.js locally with the scrubber example.
The output.timestamp fails (always zero).
Using codepen popmotion.global.min output.timestamp works.

Fake

This library seems too awesome, can you fix that ?

When user drags out of window, it should automatically let go

Problem:

If the user's mouse goes out of the window it should just let go, stop user input, etc...

Example:

screen shot 2015-10-03 at 12 04 45 am

Code:

I actually haven't take a look at the source code yet, so don't know how this could be done, I just noticed it while playing around at popmotion.
Once I take a look, I might find a solution!

everything is being called twice

When an actor or tween or simulate is being called, it happens twice. A onComplete: function(){ console.log('completed');} would replicate this.

Using Redshift with virtual-dom

Hello, your project looks interesting 👍

Now as you say Redshift

... provides DOM support for ease-of-use but provides the ability to work with raw numbers and custom callbacks for total creative freedom...

...I wonder, what would be the best practice to use Redshift in conjunction with virtual-dom (which does its own dom updates/diffing) -> https://github.com/Matt-Esch/virtual-dom

I'm using virtual-hyperscript (provided by virtual-dom) to create a so called vtree, a representation of virtual dom nodes, which are updated/diffed with the real dom -> https://github.com/Matt-Esch/virtual-dom/blob/master/virtual-hyperscript/README.md

.run() chokes at velocities lower than ~20

This is probably a combination of the default maxInactiveFrames being too low, and something to do with the filter for output values lower than x.

Some solutions:

  1. Raise default maxInactiveFrames
  2. Lower filter values
  3. Provide an Action option to prevent automatic .run() stopping

Bug with Actor.sync() and starting an Action within the frame while the frame is being updated

  • Creating an Actor fires Actor.sync()
  • Actor.sync() activates a blank Action
  • If another process (ie a Sequence) starts another action (ie Tween) on that Actor, the blank Action reference is swapped out for the Tween

This stems from the fact the activeActions list can be updated while actions are being processed - one approach would be to adopt the same management system as seen with Processes, where they get locked down at the start of the frame and updates are applied at the end.

cannot find module

Hi, when i try use popmotion with browserify i get this error:

[10:50:00] Error Cannot find module '../inc/Queue' from '/node_modules/popmotion/lib/actor'
[10:50:00] Error Cannot find module '../inc/History.js' from '/node_modules/popmotion/lib/input'
[10:50:00] Error Cannot find module '../input/Pointer' from '/node_modules/popmotion/lib/actions'
[10:50:19] Error Cannot find module '../inc/Queue' from '/node_modules/popmotion/lib/actor'
[10:50:19] Error Cannot find module '../inc/History.js' from '/node_modules/popmotion/lib/input'
[10:50:19] Error Cannot find module '../input/Pointer' from '/node_modules/popmotion/lib/actions'

Cannot select text in input field

This happens after some animations play. It is still possible to select input text via dblclick but it's impossible to do this by dragging a mouse pointer. Form is inside a tracked and animated element.
Is there a way to remove popmotion instance from a connected element?

CodePen demo: http://codepen.io/anon/pen/OygYgB

Feature Request: Actor Collision Detection

Hey all, love the library thus far - it's been a blast integrating it with my current project. Just one thing though - it would be magnificent if actors could behave naturally when colliding with one another. Are there any plans to add collision detection to the physics API?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.