Published
Edited
Oct 14, 2019
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
position = (u, v) => {
return new THREE.Vector3(
Math.sin(u) * (7 + Math.cos(u/3 - 2*v) + 2 * Math.cos(u/3 + v)),
Math.cos(u) * (7 + Math.cos(u/3 - 2*v) + 2 * Math.cos(u/3 + v)),
Math.sin(u/3 - 2*v) + 2 * Math.sin(u/3 + v)
);
}
Insert cell
Insert cell
umbilicTorus = {
const meshes = [];

const du = Math.PI / 20;
const dv = Math.PI / 20;
d3.range(-Math.PI, Math.PI, du).forEach(u => {
d3.range(-Math.PI, Math.PI, dv).forEach(v => {
const param = [
{u: u, v: v },
{u: u+du, v: v },
{u: u+du, v: v+dv},
{u: u, v: v+dv}
];

meshes.push(rect(
...param.map(p => position(p.u, p.v)),
materials[material]
));
});
});

return meshes;
}
Insert cell
Insert cell
// Make a Plane mesh with specified Material
rect = (v1, v2, v3, v4, material) => {
const planeGeometry = new THREE.Geometry();
// add vertices
[v1, v2, v3, v4].forEach(v => planeGeometry.vertices.push(v));
// add faces
planeGeometry.faces.push(new THREE.Face3(0, 1, 2));
planeGeometry.faces.push(new THREE.Face3(2, 3, 0));
planeGeometry.computeFaceNormals();
// mesh
const plane = new THREE.Mesh( planeGeometry, material );
return plane;
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
umbilicTorus.forEach(m => scene.add(m));
return scene;
}
Insert cell
camera = {
const fov = 45;
const aspect = width / height;
const near = 0.1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(20, 10, 10)
camera.lookAt(new THREE.Vector3(0, 0, 0));
return camera;
}
Insert cell
Insert cell
Insert cell
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