Merge pull request #340 from tidalcycles/animate

more animate functions + mini repl fix
This commit is contained in:
Felix Roos 2023-01-02 00:30:16 +01:00 committed by GitHub
commit 1a6b649fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import { controls, Pattern, getDrawContext, silence, scheduler } from './index.mjs';
import { controls, Pattern, getDrawContext, silence, register, pure } from './index.mjs';
const { createParams } = controls;
let clearColor = '#22222210';
@ -12,13 +12,13 @@ Pattern.prototype.animate = function ({ callback, sync = false, smear = 0.5 } =
clearColor = `#200010${smearPart}`;
const render = (t) => {
let frame;
if (sync) {
/* if (sync) {
t = scheduler.now();
frame = this.queryArc(t, t);
} else {
t = Math.round(t);
frame = this.slow(1000).queryArc(t, t);
}
} else { */
t = Math.round(t);
frame = this.slow(1000).queryArc(t, t);
// }
ctx.fillStyle = clearColor;
ctx.fillRect(0, 0, ww, wh);
frame.forEach((f) => {
@ -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 moveXY = register('moveXY', function (dx, dy, pat) {
return pat.add(x(dx).y(dy));
});
export const zoomIn = register('zoomIn', function (f, pat) {
const d = pure(1).sub(f).div(2);
return pat.rescale(f).move(d, d);
});

View File

@ -3,10 +3,6 @@ import { evaluate as _evaluate } from './evaluate.mjs';
import { logger } from './logger.mjs';
import { setTime } from './time.mjs';
export let scheduler; // expose scheduler to global scope
// this is not optimal as it will only work for one repl at a time
// TODO: use pattern.context to expose scheduler
export function repl({
interval,
defaultOutput,
@ -18,7 +14,7 @@ export function repl({
transpiler,
onToggle,
}) {
scheduler = new Cyclist({
const scheduler = new Cyclist({
interval,
onTrigger: async (hap, deadline, duration) => {
try {