summaryrefslogtreecommitdiff
path: root/src/scenes
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-02-08 18:36:10 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-02-08 18:36:10 -0700
commit5b8b3abcba8746502014266583907421b71a330b (patch)
treefc3d8a2159a17c8af1d432d93307ff01474fb053 /src/scenes
parentc18b81b2f26123481558cb3fffc794c2c13f74ad (diff)
downloadcompiling-the-lambda-calculus-5b8b3abcba8746502014266583907421b71a330b.tar.gz
compiling-the-lambda-calculus-5b8b3abcba8746502014266583907421b71a330b.zip
add hungry partner function
Diffstat (limited to 'src/scenes')
-rw-r--r--src/scenes/first_box.tsx23
-rw-r--r--src/scenes/hungry_partner.meta5
-rw-r--r--src/scenes/hungry_partner.tsx108
-rw-r--r--src/scenes/index.ts14
4 files changed, 136 insertions, 14 deletions
diff --git a/src/scenes/first_box.tsx b/src/scenes/first_box.tsx
index b3957af..31ee631 100644
--- a/src/scenes/first_box.tsx
+++ b/src/scenes/first_box.tsx
@@ -4,8 +4,6 @@ import {
beginSlide,
createRef,
slideTransition,
- all,
- waitFor,
} from "@motion-canvas/core";
import { FunctionBox } from "../components/function_box";
@@ -23,14 +21,15 @@ export default makeScene2D(function* (view) {
yield* beginSlide("Black Box");
- for (const [a, b] of [
- [-1, 2],
+ for (const [[a, b], i] of [
+ [1, 2],
[3, 4],
- [5, 6],
- ] as [number, number][]) {
- const inputId = "(" + [a, b].join(",") + ")";
+ [1, 2],
+ [1, 2],
+ ].map((x, i) => [x, i]) as [[number, number], number][]) {
+ const inputId = "(" + [a, b, i].join(",") + ")";
- yield* all(functionBox().reset(0.25));
+ yield* functionBox().reset(0.5);
yield* functionBox().setInputs([{ val: a }, { val: b }], 0.5);
yield* beginSlide("Add Inputs " + inputId);
@@ -41,4 +40,12 @@ export default makeScene2D(function* (view) {
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");
});
diff --git a/src/scenes/hungry_partner.meta b/src/scenes/hungry_partner.meta
new file mode 100644
index 0000000..cec20cc
--- /dev/null
+++ b/src/scenes/hungry_partner.meta
@@ -0,0 +1,5 @@
+{
+ "version": 0,
+ "timeEvents": [],
+ "seed": 3141613664
+} \ No newline at end of file
diff --git a/src/scenes/hungry_partner.tsx b/src/scenes/hungry_partner.tsx
new file mode 100644
index 0000000..696870e
--- /dev/null
+++ b/src/scenes/hungry_partner.tsx
@@ -0,0 +1,108 @@
+import { Node, Txt, makeScene2D } from "@motion-canvas/2d";
+import {
+ Direction,
+ beginSlide,
+ createRef,
+ slideTransition,
+} from "@motion-canvas/core";
+
+import { FunctionBox } from "../components/function_box";
+import { theme } from "../theme";
+
+const hungryValentine = `(
+ savoryCravingRatio: number, sweetCravingRatio: number,
+ acidityCravingRatio: number, spiceCravingRatio: number,
+): string => {
+ const foods = {
+ "🍕": {savory: 0.8, sweet: 0.1, acidity: 0.5, spice: 0.5},
+ "🧁": {savory: 0.2, sweet: 0.9, acidity: 0.1, spice: 0.1},
+ "🍋🍰": {savory: 0.1, sweet: 0.8, acidity: 0.9, spice: 0.1},
+ "🌮🔥": {savory: 0.6, sweet: 0.2, acidity: 0.5, spice: 0.8},
+ };
+
+ const weight = (foodProfile: Record<string, number>) =>
+ foodProfile["savory"] * savoryCravingRatio
+ + foodProfile["sweet"] * sweetCravingRatio
+ + foodProfile["acidity"] * acidityCravingRatio
+ + foodProfile["spice"] * spiceCravingRatio;
+
+ const bestFood = Object.keys(foods).reduce((a, b) =>
+ weight(foods[a]) > weight(foods[b]) ? a : b
+ );
+
+ const foodNames = Array.from(Object.keys(foods));
+ const shouldChooseRandom = Math.random() > 0.4; // side effect
+ return shouldChooseRandom
+ ? foodNames[Math.floor(Math.random() * foodNames.length)]
+ : bestFood;
+};`;
+
+export default makeScene2D(function* (view) {
+ const functionBox = createRef<FunctionBox>();
+
+ view.add(
+ <FunctionBox
+ arity={4}
+ idlingText={"😴"}
+ workingText={"😋💭"}
+ source={hungryValentine}
+ ref={functionBox}
+ />,
+ );
+
+ yield* slideTransition(Direction.Right);
+
+ yield* beginSlide("Get Best Food For Partner");
+
+ const order = ["savory", "sweet", "acidic", "spice"];
+
+ 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: (
+ <Txt fontFamily={theme.font} fill={theme.text.hex}>
+ {order[i]}:{" "}
+ <Txt
+ fontFamily={theme.font}
+ fill={
+ ratio > 0.6
+ ? theme.red.hex
+ : ratio < 0.3
+ ? theme.green.hex
+ : theme.lavender.hex
+ }
+ >
+ {ratio.toString()}
+ </Txt>
+ </Txt>
+ ),
+ })),
+ 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");
+});
diff --git a/src/scenes/index.ts b/src/scenes/index.ts
index 56fda2b..d21da3b 100644
--- a/src/scenes/index.ts
+++ b/src/scenes/index.ts
@@ -4,12 +4,14 @@ import partone from "./partone?scene";
import flirtingwithfunctions from "./flirtingwithfunctions?scene";
import doctor from "./doctor?scene";
import first_box from "./first_box?scene";
+import hungry_partner from "./hungry_partner?scene";
export const scenes = [
- title,
- me,
- partone,
- flirtingwithfunctions,
- doctor,
- first_box,
+ // title,
+ // me,
+ // partone,
+ // flirtingwithfunctions,
+ // doctor,
+ // first_box,
+ hungry_partner,
];