From 9db4283a20d4ea751d21a8f04a49d3d95d527ac5 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 11 Feb 2024 16:38:36 -0700 Subject: updates --- src/scenes/hungry_partner.tsx | 92 ++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 40 deletions(-) (limited to 'src/scenes/hungry_partner.tsx') diff --git a/src/scenes/hungry_partner.tsx b/src/scenes/hungry_partner.tsx index 696870e..5198daf 100644 --- a/src/scenes/hungry_partner.tsx +++ b/src/scenes/hungry_partner.tsx @@ -1,8 +1,10 @@ -import { Node, Txt, makeScene2D } from "@motion-canvas/2d"; +import { Layout, Txt, makeScene2D } from "@motion-canvas/2d"; import { Direction, beginSlide, - createRef, + range, + all, + makeRef, slideTransition, } from "@motion-canvas/core"; @@ -31,23 +33,27 @@ const hungryValentine = `( ); const foodNames = Array.from(Object.keys(foods)); - const shouldChooseRandom = Math.random() > 0.4; // side effect + const shouldChooseRandom = Math.random() > 0.7; // side effect return shouldChooseRandom ? foodNames[Math.floor(Math.random() * foodNames.length)] : bestFood; };`; export default makeScene2D(function* (view) { - const functionBox = createRef(); + const functionBoxes: FunctionBox[] = []; view.add( - , + + {range(3).map((i) => ( + + ))} + , ); yield* slideTransition(Direction.Right); @@ -59,50 +65,56 @@ export default makeScene2D(function* (view) { for (const [[a, b, c, d], i] of [ [0.7, 0.1, 0.4, 0.1], [0.7, 0.1, 0.4, 0.1], - [0.7, 0.1, 0.4, 0.1], - [0.7, 0.1, 0.4, 0.1], ].map((x, i) => [x, i]) as [[number, number, number, number], number][]) { const inputId = "(" + [a, b, c, d, i].join(",") + ")"; - yield* functionBox().reset(0.5); - yield* functionBox().setInputs( - [a, b, c, d].map((ratio, i) => ({ - val: ratio, - node: ( - - {order[i]}:{" "} - 0.6 - ? theme.red.hex - : ratio < 0.3 - ? theme.green.hex - : theme.lavender.hex - } - > - {ratio.toString()} - - + yield* all(...functionBoxes.map((box) => box.reset(0.5))); + + yield* all( + ...functionBoxes.map((box) => + box.setInputs( + [a, b, c, d].map((ratio, i) => ({ + val: ratio, + node: ( + + {order[i]}:{" "} + 0.6 + ? theme.red.hex + : ratio < 0.3 + ? theme.green.hex + : theme.lavender.hex + } + > + {ratio.toString()} + + + ), + })), + 0.5, ), - })), - 0.5, + ), ); yield* beginSlide("Add Inputs " + inputId); + yield* all(...functionBoxes.map((box) => box.propogateInput(0.5))); - yield* functionBox().propogateInput(0.5); yield* beginSlide("Propogate Inputs " + inputId); - yield* functionBox().propogateOutput(0.5); + yield* all(...functionBoxes.map((box) => box.propogateOutput(0.5))); yield* beginSlide("Propogate Outputs of " + inputId); } - yield* functionBox().reset(0.5); + yield* all(...functionBoxes.map((box) => box.reset(0.5))); + + functionBoxes.slice(1).map((box) => box.remove()); - yield* functionBox().showCode(0.85); + const [root] = functionBoxes; + yield* root.showCode(0.85); yield* beginSlide("Show Code"); - yield* functionBox().hideCode(0.85); + yield* root.hideCode(0.85); yield* beginSlide("Hide Code"); }); -- cgit v1.2.3-70-g09d2