From 28912fff9723c5fb7e62e8ed78925b8660fc0897 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 1 Jan 2023 18:47:45 +0100 Subject: [PATCH] animate: rescale + move + zoom --- packages/core/animate.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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); +});