diff --git a/packages/core/animate.mjs b/packages/core/animate.mjs index 6da97f08..39d1da6d 100644 --- a/packages/core/animate.mjs +++ b/packages/core/animate.mjs @@ -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); +});