speice.io/blog/2024-11-15-playing-with-fire/2-transforms/baseline.ts

22 lines
624 B
TypeScript
Raw Normal View History

2024-11-19 21:42:03 -05:00
// hidden-start
import { Coefs } from './coefs'
import { Variation } from './variations'
// hidden-end
export function applyTransform(
x: number,
y: number,
coefs: Coefs,
variations: [number, Variation][])
{
const transformX = coefs.a * x + coefs.b * y + coefs.c;
const transformY = coefs.d * x + coefs.e * y + coefs.f;
var finalX = 0;
var finalY = 0;
for (const [blend, variation] of variations) {
const [variationX, variationY] = variation(transformX, transformY);
finalX += blend * variationX;
finalY += blend * variationY;
}
return [finalX, finalY];
}