Skip to content

Commit aeb53db

Browse files
committed
Add evolve step
1 parent a56c762 commit aeb53db

File tree

2 files changed

+960
-395
lines changed

2 files changed

+960
-395
lines changed

media/src/stories/Lagrange.svelte

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
filterBang,
1010
gaussLegendre,
1111
sampleImplicitSurface,
12+
evolveFlowOnLevel,
1213
} from '../utils';
1314
import { mathToJSFunction } from '../objects/mathutils';
1415
import { onMount, onDestroy, untrack } from 'svelte';
@@ -78,7 +79,7 @@
7879
let edgesUp = $state();
7980
8081
const plusMaterial = new THREE.MeshStandardMaterial({
81-
color: 0xccddff,
82+
color: 0x000000,
8283
side: THREE.DoubleSide,
8384
roughness: 0.4,
8485
metalness: 0.8,
@@ -97,7 +98,7 @@
9798
boxes.visible = boxesVisible;
9899
});
99100
100-
let nBoxes = $state(10);
101+
let nBoxes = $state(5);
101102
let boxing = false;
102103
103104
let x0 = $derived(math.parse(currentSurface.params.a).evaluate());
@@ -111,14 +112,17 @@
111112
);
112113
113114
let pts = $derived(
114-
sampleImplicitSurface(g, [
115-
[x0, x1],
116-
[y0, y1],
117-
[z0, z1],
115+
sampleImplicitSurface(
116+
g,
117+
[
118+
[x0, x1],
119+
[y0, y1],
120+
[z0, z1],
121+
],
118122
nBoxes,
119123
nBoxes,
120124
nBoxes,
121-
]),
125+
),
122126
);
123127
124128
$inspect(pts);
@@ -159,6 +163,25 @@
159163
// demoObjects.push(currentSurface);
160164
});
161165
});
166+
167+
const F = (x, y, z) => [x, y, 1 / 13];
168+
169+
let req;
170+
171+
function go() {
172+
boxes.children.forEach((b) => {
173+
const [px, py, pz] = evolveFlowOnLevel(
174+
F,
175+
g,
176+
[b.position.x, b.position.y, b.position.z],
177+
0.01,
178+
);
179+
180+
b.position.set(px, py, pz);
181+
});
182+
render();
183+
req = requestAnimationFrame(go);
184+
}
162185
</script>
163186
164187
<div>
@@ -173,6 +196,16 @@
173196
step="1"
174197
max="20"
175198
/>
199+
<button
200+
onclick={() => {
201+
if (req) {
202+
cancelAnimationFrame(req);
203+
req = undefined;
204+
} else {
205+
go();
206+
}
207+
}}>Evolve</button
208+
>
176209
</div>
177210
178211
<style>

0 commit comments

Comments
 (0)