Public
Edited
Apr 21, 2023
3 stars
Also listed in…
Math
Insert cell
Insert cell
Insert cell
Insert cell
run_it = {
// Should do:
let coord = d3.select(anim).select("#surface").selectAll("coordinate");

// For illustrative purposes involving embedding:
// let coord = d3.select("#surface").selectAll("coordinate");

// In either case, we'll modify according to the dynamica variable now:
let coord_string = make_coord_string(
(x, y) => [x, y, f(x, y, now / 700)],
[-1, 1],
[-1, 1]
);
coord.attr("point", coord_string);
}
Insert cell
function f(x, y, t) {
// inward ripple wave
let phase1 =
(0.5 +
0.5 *
Math.sin(t / 40 + 0 * Math.PI + 0.5 * Math.sqrt(x ** 2 + y ** 2))) **
2;
let rippleWave = Math.cos(2 * t + 25 * Math.sqrt(0.2 + x ** 2 + y ** 2));

// outward spiral wave
let phase2 =
(0.5 +
0.5 *
Math.sin(t / 40 + 0.75 * Math.PI - 0.5 * Math.sqrt(x ** 2 + y ** 2))) **
2;
let spiralWave =
0 +
(Math.cos(
// wave shape
-2 * t + // animate
18 * Math.sqrt(0.2 + x ** 2 + y ** 2) - // outward ripple
2 * Math.atan((x + 0.001) / y) // spiral ramp
) *
(x ** 2 + y ** 2)) /
(x ** 2 + y ** 2 + 0.03) + // smooth roughness near origin
1 -
(0.75 * (x ** 2 + y ** 2)) / (x ** 2 + y ** 2 + 0.03); // adds a bump so the spiral arms connect

// chaotic inverse wave
let phase3 = 1.1 - Math.min(1.1, phase1 + phase2);
let inverseWave = Math.sin(
(25 * (x * y)) / Math.sqrt(1 + x ** 2 + y ** 2) - t
);

return (
0.15 * phase1 * rippleWave +
0.12 * phase2 * spiralWave +
0.15 * phase3 * inverseWave +
0.3
);
}

// Original function for the posted question on talk.observablehq.com

// function f(x, y, t) {
// x = 2 * x - 1;
// y = 2 * y - 1;
// return (
// 0.5 *
// Math.sin(
// 3 * t + 2 * Math.atan((x + 0.001) / y) - 15 * Math.sqrt(x ** 2 + y ** 2)
// ) *
// (1 - Math.cos(4.5 * Math.sqrt(x ** 2 + y ** 2))) +
// 0.5 * Math.sin(10 * Math.sqrt(x ** 2 + y ** 2) - 2 * t)
// );
// }
Insert cell
import {
make_coord_string,
create_surface,
show_x3d
} from "@mcmcclur/parametric-surfaces"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more