tslerp
Typescript library for lerping single and multi-sample data sets over time across a variety of styles and transitions.
Build Status
Master Branch
Develop Branch
End User Documentation
Installation
- Add the package to your 'dependencies' list in
package.json
and run npm install
"tslerp": "^2.0.0"
Optionally, you can manually install the package using the npm command line
npm install tslerp --save
- Add tslerp to both your
map
and packages
structures in systemjs.config.js
var map = {
...
'tslerp': 'node_modules/tslerp'
};
var packages = {
...
'tslerp': { main: 'index.js', defaultExtension: 'js' },
};
- Optionally, add the
rootDir
option to tsconfig.json
to make sure TypeScript's default root path algorithm doesn't pull in the node_modules
folder
Usage
Examples of using tslerp can also be found in the tslerp test packages in lerp.spec.ts
Triggering a simple lerp
import { TsLerp } from 'tslerp';
class ClassToLerpSomething {
private tsLerp: TsLerp = new TsLerp();
public startTransition() {
this.tsLerp.define([ [0, 10], [30, 50] ], 10);
this.tsLerp.lerp((results: number[], time: number) => {
this.lerpCallback(results, time);
});
}
private lerpCallback(results: number[], time: number) {
}
}
Chaining lerp sequences
import { TsLerp } from 'tslerp';
class ClassToLerpSomething {
...
private lerpCallback(results: number[], time: number) {
if (time === 1) {
this.tsLerp.define([ [10, 100] ], 5);
this.tsLerp.lerp((results: number[], time: number) => {
this.lerpCallback(results, time);
});
}
}
}
Controlling an in-progress lerp
It is possible to pause or delay an in-progress lerp in response to external events
import { TsLerp } from 'tslerp';
class ClassToLerpSomething {
...
private onSomeEventToPause() {
this.tsLerp.pause(true);
...
}
private onSomeEventToResume() {
this.tsLerp.pause(false);
...
}
private onSomeEventToStop() {
this.tsLerp.stop()
...
}
}
Styling a lerp transition
TsLerp.define
allows you to specify the kind of transition and style the lerp will travel.
import { TsLerp, TsLerpTransition, TsLerpStyle } from 'tslerp';
class ClassToLerpSomething {
...
public startTransition() {
this.tsLerp.define([ [0, 10], [30, 50] ], 10, TsLerpTransition.EaseOut, TsLerpStyle.Quadratic);
...
}
private lerpCallback(results: number[], time: number) {
}
}
The following animations show the various transitions and styles available, samples over a 1 second period. All animations were captured from Easing Equations by Robert Penner
Style: Linear
Note that the TsLerpTransition
option is ignored when choosing a Linear style
Style: Quadratic
Transition: Ease In
Transition: Ease Out
Transition: Ease In and Out
Style: Sine
Transition: Ease In
Transition: Ease Out
Transition: Ease In and Out
Cubic
Transition: Ease In
Transition: Ease Out
Transition: Ease In and Out
Style: Exponential
Transition: Ease In
Transition: Ease Out
Transition: Ease In and Out
Change Log
2.0.0
- Removed Typings dependency
1.0.5
- Updated project to latest TypeScript (v2.3.2) and fixed resultant errors
1.0.4
- Documentation update stating Typings as a Dependency
1.0.3
- Updated package requirements to Typescript ^2.0.0 plus related package upgrades
1.0.2
1.0.1
1.0.0
- Added support for Linear, Sine, Cubic and Exponential styles
- Added support for Ease In, Out and In/Out transitions for all styles
0.0.1
- Initial release
- Support for Ease In Quadratic lerps only
Contribution Guidelines
Requirements
Optional
Development
- Branch from */develop
- Browse to /development and run
npm install
- Compile by running
tsc
(by default this will watch for changes) - Run tests in watch mode by running
npm run-script testdev
Merging Back
- Raise a pull request which will run a set of Travis-CI tests
- Once passed, the change will be squashed into develop if approved