animate: rescale + move + zoom

This commit is contained in:
Felix Roos 2023-01-01 18:47:45 +01:00
parent 0abd062e5c
commit 28912fff97

View File

@ -1,4 +1,4 @@
import { controls, Pattern, getDrawContext, silence, scheduler } from './index.mjs';
import { controls, Pattern, getDrawContext, silence, scheduler, register, pure } from './index.mjs';
const { createParams } = controls;
let clearColor = '#22222210';
@ -52,3 +52,16 @@ Pattern.prototype.animate = function ({ callback, sync = false, smear = 0.5 } =
};
export const { x, y, w, h, a, r, fill, smear } = createParams('x', 'y', 'w', 'h', 'a', 'r', 'fill', 'smear');
export const rescale = register('rescale', function (f, pat) {
return pat.mul(x(f).w(f).y(f).h(f));
});
export const move = register('move', function (dx, dy, pat) {
return pat.add(x(dx).y(dy));
});
export const zoom = register('zoom', function (f, pat) {
const d = pure(1).sub(f).div(2);
return pat.rescale(f).move(d, d);
});