1
Fork 0
This commit is contained in:
stysmmaker 2021-04-13 20:46:25 -04:00
parent fb927e5bcd
commit 45d52d8749
Signed by: mmaker
GPG Key ID: CCE79B8FEDA40FB2
2 changed files with 107 additions and 107 deletions

View File

@ -1,30 +1,30 @@
import typescript from '@rollup/plugin-typescript'; import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace'; import replace from '@rollup/plugin-replace';
import afterEffectJsx from 'rollup-plugin-ae-jsx'; import afterEffectJsx from 'rollup-plugin-ae-jsx';
import pkg from './package.json'; import pkg from './package.json';
export default { export default {
input: 'src/index.ts', input: 'src/index.ts',
output: { output: {
file: pkg.main, file: pkg.main,
format: 'cjs', format: 'cjs',
format: 'es', format: 'es',
}, },
external: Object.keys(pkg.dependencies), external: Object.keys(pkg.dependencies),
plugins: [ plugins: [
replace({ replace({
preventAssignment: true, preventAssignment: true,
values: { values: {
_npmVersion: pkg.version, _npmVersion: pkg.version,
}, },
}), }),
typescript({ typescript({
module: 'esnext', module: 'esnext',
target: 'esnext', target: 'esnext',
noImplicitAny: true, noImplicitAny: true,
moduleResolution: 'node', moduleResolution: 'node',
strict: true, strict: true,
}), }),
afterEffectJsx(), afterEffectJsx(),
], ],
}; };

View File

@ -1,78 +1,78 @@
import { Comp, Layer } from 'expression-globals-typescript'; import { Comp, Layer } from 'expression-globals-typescript';
const version = '_npmVersion'; const version = '_npmVersion';
const thisComp = new Comp(); const thisComp = new Comp();
const thisLayer = new Layer(); const thisLayer = new Layer();
let thisProperty; let thisProperty;
function get_functions(time: number = thisLayer.time) function get_functions(time: number = thisLayer.time)
{ {
function get_key_index(forward = false, input_property = thisProperty) function get_key_index(forward = false, input_property = thisProperty)
{ {
let n = 0; let n = 0;
if (input_property.numKeys > 0) if (input_property.numKeys > 0)
{ {
n = input_property.nearestKey(time).index; n = input_property.nearestKey(time).index;
if (input_property.key(n).time > time && !forward) n--; if (input_property.key(n).time > time && !forward) n--;
else if (input_property.key(n).time <= time && forward) n++; else if (input_property.key(n).time <= time && forward) n++;
} }
return Math.min(n, input_property.numKeys); return Math.min(n, input_property.numKeys);
} }
function angle_offset(rot: number, pos: number) function angle_offset(rot: number, pos: number)
{ {
rot = thisLayer.degreesToRadians(rot - 90); rot = thisLayer.degreesToRadians(rot - 90);
const x = Math.cos(rot); const x = Math.cos(rot);
const y = Math.sin(rot); const y = Math.sin(rot);
return [pos*x, pos*y]; return [pos*x, pos*y];
} }
// https://gist.github.com/animoplex/aafd6a157282351c8dfeea385d969ef2 // https://gist.github.com/animoplex/aafd6a157282351c8dfeea385d969ef2
function inertial_bounce(amp: number, freq: number, decay: number, input_property = thisProperty) function inertial_bounce(amp: number, freq: number, decay: number, input_property = thisProperty)
{ {
const n = get_key_index(); const n = get_key_index();
let t = 0; let t = 0;
if (n != 0) if (n != 0)
{ {
t = time - input_property.key(n).time; t = time - input_property.key(n).time;
} }
if (n > 0 && t < 1) if (n > 0 && t < 1)
{ {
const v = input_property.velocityAtTime(input_property.key(n).time - thisComp.frameDuration/10); const v = input_property.velocityAtTime(input_property.key(n).time - thisComp.frameDuration/10);
return input_property.value + v * (amp / 100) * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay*t); return input_property.value + v * (amp / 100) * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay*t);
} }
else else
{ {
return t; return t;
} }
} }
const YTPMV = { const YTPMV = {
flip: function(mult = 100, input_property = thisProperty) flip: function(mult = 100, input_property = thisProperty)
{ {
const n = get_key_index(input_property); const n = get_key_index(input_property);
return (n % 2 != 0 || n == 0) ? 1*mult : -mult; return (n % 2 != 0 || n == 0) ? 1*mult : -mult;
}, },
time_reset: function(input_property = thisProperty) time_reset: function(input_property = thisProperty)
{ {
const n = get_key_index(undefined, input_property); const n = get_key_index(undefined, input_property);
return (n > 0) ? time - input_property.key(n).time : 0; return (n > 0) ? time - input_property.key(n).time : 0;
} }
}; };
return { return {
get_key_index, get_key_index,
angle_offset, angle_offset,
inertial_bounce, inertial_bounce,
YTPMV YTPMV
}; };
} }
export { export {
version, version,
get_functions get_functions
}; };