Skip to content

feat(core): spawn function#951

Merged
aarthificial merged 1 commit intomotion-canvas:mainfrom
aarthificial:spawn
Feb 10, 2024
Merged

feat(core): spawn function#951
aarthificial merged 1 commit intomotion-canvas:mainfrom
aarthificial:spawn

Conversation

@aarthificial
Copy link
Contributor

Makes it possible to run generators concurrently without having to yield them:

spawn(function*() {
  yield* rect().opacity(0, 1);
})

Or:

spawn(rect().opacity(0, 1))

Together with ref it makes it easy to run animations upon adding the node to the tree:

import {Circle, makeScene2D} from '@motion-canvas/2d';
import {waitFor} from '@motion-canvas/core';
import {spawn} from '@motion-canvas/core/lib/threading/spawn';

export default makeScene2D(function* (view) {
  view.add(
    <Circle
      ref={node => spawn(node.scale(1, 1))}
      scale={0}
      width={320}
      height={320}
      fill={'lightseagreen'}
    />,
  );

  yield* waitFor(5);
});

However we still need to improve the typing of ref to make it truly useful. Right now it's always typed as the base Node class.

@aarthificial aarthificial merged commit 51d8cf0 into motion-canvas:main Feb 10, 2024
@aarthificial aarthificial deleted the spawn branch February 10, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant