Merge pull request #340 from tidalcycles/animate
more animate functions + mini repl fix
This commit is contained in:
commit
1a6b649fd6
2 changed files with 20 additions and 11 deletions
|
|
@ -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;
|
const { createParams } = controls;
|
||||||
|
|
||||||
let clearColor = '#22222210';
|
let clearColor = '#22222210';
|
||||||
|
|
@ -12,13 +12,13 @@ Pattern.prototype.animate = function ({ callback, sync = false, smear = 0.5 } =
|
||||||
clearColor = `#200010${smearPart}`;
|
clearColor = `#200010${smearPart}`;
|
||||||
const render = (t) => {
|
const render = (t) => {
|
||||||
let frame;
|
let frame;
|
||||||
if (sync) {
|
/* if (sync) {
|
||||||
t = scheduler.now();
|
t = scheduler.now();
|
||||||
frame = this.queryArc(t, t);
|
frame = this.queryArc(t, t);
|
||||||
} else {
|
} else { */
|
||||||
t = Math.round(t);
|
t = Math.round(t);
|
||||||
frame = this.slow(1000).queryArc(t, t);
|
frame = this.slow(1000).queryArc(t, t);
|
||||||
}
|
// }
|
||||||
ctx.fillStyle = clearColor;
|
ctx.fillStyle = clearColor;
|
||||||
ctx.fillRect(0, 0, ww, wh);
|
ctx.fillRect(0, 0, ww, wh);
|
||||||
frame.forEach((f) => {
|
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 { 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);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,6 @@ import { evaluate as _evaluate } from './evaluate.mjs';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
import { setTime } from './time.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({
|
export function repl({
|
||||||
interval,
|
interval,
|
||||||
defaultOutput,
|
defaultOutput,
|
||||||
|
|
@ -18,7 +14,7 @@ export function repl({
|
||||||
transpiler,
|
transpiler,
|
||||||
onToggle,
|
onToggle,
|
||||||
}) {
|
}) {
|
||||||
scheduler = new Cyclist({
|
const scheduler = new Cyclist({
|
||||||
interval,
|
interval,
|
||||||
onTrigger: async (hap, deadline, duration) => {
|
onTrigger: async (hap, deadline, duration) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue