summaryrefslogtreecommitdiff
path: root/src/scenes/first_box.tsx
blob: 31ee631b2a3e3f63b14983eb29900c92f433aed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { makeScene2D } from "@motion-canvas/2d";
import {
  Direction,
  beginSlide,
  createRef,
  slideTransition,
} from "@motion-canvas/core";

import { FunctionBox } from "../components/function_box";

const add = `(a: number, b: number) => {
  return a + b;
}`;

export default makeScene2D(function* (view) {
  const functionBox = createRef<FunctionBox>();

  view.add(<FunctionBox arity={2} source={add} ref={functionBox} />);

  yield* slideTransition(Direction.Left);

  yield* beginSlide("Black Box");

  for (const [[a, b], i] of [
    [1, 2],
    [3, 4],
    [1, 2],
    [1, 2],
  ].map((x, i) => [x, i]) as [[number, number], number][]) {
    const inputId = "(" + [a, b, i].join(",") + ")";

    yield* functionBox().reset(0.5);
    yield* functionBox().setInputs([{ val: a }, { val: b }], 0.5);

    yield* beginSlide("Add Inputs " + inputId);

    yield* functionBox().propogateInput(0.5);
    yield* beginSlide("Propogate Inputs " + inputId);

    yield* functionBox().propogateOutput(0.5);
    yield* beginSlide("Propogate Outputs of " + inputId);
  }

  yield* functionBox().reset(0.5);

  yield* functionBox().showCode(0.85);
  yield* beginSlide("Show Code");

  yield* functionBox().hideCode(0.85);
  yield* beginSlide("Hide Code");
});