Published
Edited
Jul 24, 2020
2 forks
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
replay;
const scene = new THREE.Scene();

const [[w, animate, particleSize], [sigma, beta, rho]] = values;

if (!animate) {
const controls = new THREE.OrbitControls(camera, renderer.domElement);
invalidation.then(() => (controls.dispose(), renderer.dispose()));
controls.addEventListener("change", () => renderer.render(scene, camera));
}

const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(startPositions, 3)
);
const material = new THREE.PointsMaterial({
size: particleSize,
color: 0xffffff,
transparent: true,
opacity: 0.2
});
const points = new THREE.Points(geometry, material);
points.position.z = -Math.sqrt(w);
scene.add(points);

let t = 0;
const dt = 0.01;
const positions = points.geometry.attributes.position.array;

while (true) {
t += dt;
await Promises.delay(10);

if (animate) {
camera.lookAt(new THREE.Vector3(0, 0, 0));
camera.position.x = Math.sin(t / 2) * camOffset;
camera.position.z = Math.cos(t / 2) * camOffset;
}

for (let i = 0; i < positions.length; ++i) {
if (i % 3 === 0) {
// dx = sigma(y - x) dt
const dx = sigma * (positions[i + 1] - positions[i]) * dt;
positions[i] += dx;
}
if (i % 3 === 1) {
// dy = x(rho - z) - y dt
const dy =
(positions[i - 1] * (rho - positions[i + 1]) - positions[i]) * dt;
positions[i] += dy;
}
if (i % 3 === 2) {
// dz = xy - beta z dt
const dz =
(positions[i - 2] * positions[i - 1] - beta * positions[i]) * dt;
positions[i] += dz;
}
}

points.geometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
yield renderer.domElement;
}
}
Insert cell
startPositions = {
const [[w]] = values;
const n = w * w;
const positions = [];
for (let i = 0; i < n / 2; ++i) {
const x = i % w;
const y = 0;
const z = Math.floor(i / w);
positions.push(x, y, z);
}

yield positions;
}
Insert cell
renderer = {
const renderer = new THREE.WebGLRenderer({
antialias: true,
transparent: true
});
renderer.setSize(width, height);

renderer.setPixelRatio(devicePixelRatio);
return renderer;
}
Insert cell
camera = {
const fov = 25;
const aspect = width / height;
const near = 0.001;
const far = 10000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(0, 1, -camOffset);
return camera;
}
Insert cell
camOffset = 90
Insert cell
height = width * 0.7
Insert cell
import { inputsGroup } from '@bumbeishvili/input-groups'
Insert cell
import { slider, checkbox } from '@jashkenas/inputs'
Insert cell
THREE = {
const THREE = (window.THREE = await require("three@0.110.0/build/three.min.js"));
await require("three@0.110.0/examples/js/controls/OrbitControls.js").catch(
() => {}
);
return THREE;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more