A library for adding sequences of values and smoothly transitioning between them
$ npm install sequins
const { Sequence } = require('sequins');
const sequence = new Sequence([
{
time: 0,
variables: {
x: {
value: 0,
easeNext: 'easeInOutCirc'
}
}
},
{
time: 100,
variables: {
x: {
value: 80
}
}
}
]);
console.log(sequence.exportArray(5));
// [ { time: 0, values: { x: 0 } },
// { time: 10, values: { x: 0.8081641154691521 } },
// { time: 20, values: { x: 3.3393944403532805 } },
// { time: 30, values: { x: 7.999999999999998 } },
// ...
// { time: 90, values: { x: 79.19183588453085 } },
// { time: 100, values: { x: 80 } } ]
The main functionality of this library is creating sequences and exporting them. You can export sequences in a number of different ways.
Sequence.exportArray(interval[, startTime[, endTime]]);
number
- How much time in between each instance of the exported sequence.
number
- Optional. At what time to start exporting values. Defaults to 0
.
number
- Optional. At what time to stop exporting values. Defaults to Sequence.length
.
Instance[]
- Array of instance values.
Sequence.exportGenerator(interval[, startTime[, endTime]]);
number
- How much time in between each instance of the exported sequence.
number
- Optional. At what time to start exporting values. Defaults to 0
.
number
- Optional. At what time to stop exporting values. Defaults to Sequence.length
.
IterableIterator<Instance>
- A generator function which yields
the next value in the exported sequence.
Sequence.exportInterval(delay, interval, callback[, startTime[, endTime]]);
number
- How much time in between each invocation of callback (in milliseconds).
number
- How much time in between each instance of the exported sequence.
(instance: Instance, index: number) => void
- Callback invoked every delay
. First parameter is the instance object (contains time
and values
). Second parameter is the current instance's index in the exported sequence.
number
- Optional. At what time to start exporting values. Defaults to 0
.
number
- Optional. At what time to stop exporting values. Defaults to Sequence.length
.
Nothing is returned.
An instance object represents one point on a sequence. It contains a time
property which, as the same suggests, the point of time in the sequence. It also contains a values
property, which is an object of all the current variables and their number value.
Instance {
time: number;
values: {
[name: string]: number;
};
}