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

17 lines
426 B
TypeScript
Raw Normal View History

2024-11-29 19:25:29 -05:00
// hidden-start
2024-11-30 17:35:42 -05:00
import {VariationBlend} from "../src/variationBlend";
2024-11-29 19:25:29 -05:00
// hidden-end
2024-11-30 17:35:42 -05:00
export function blend(
x: number,
y: number,
variations: VariationBlend): [number, number] {
2024-11-29 19:25:29 -05:00
let [finalX, finalY] = [0, 0];
for (const [weight, variation] of variations) {
const [varX, varY] = variation(x, y);
finalX += weight * varX;
finalY += weight * varY;
}
return [finalX, finalY];
}