Published
Edited
Nov 23, 2021
Insert cell
Insert cell
Insert cell
renderer.domElement
Insert cell
// Continuously updates
{
while (true) {
//cube[0].rotation.z += 0.01;
//cube[1].rotation.z += 0.01;
//cube[2].rotation.z += 0.01;

renderer.render(scene, camera);
yield null;
}
}
Insert cell
height = 600
Insert cell
cube = {
const cube1 = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0xff0000 })
);
cube1.position.x = -1.5;
group.add(cube1);

const cube2 = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0x0000ff })
);
cube2.position.x = 0;
group.add(cube2);

const cube3 = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0x00ff00 })
);
cube3.position.x = 1.5;
group.add(cube3);

return [cube1, cube2, cube3];
}
Insert cell
group = {
const group = new THREE.Group();
group.scale.y = 2;
group.rotation.y = 0.2;
return group;
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x001b42);
const axesHelper = new THREE.AxesHelper(2);
scene.add(axesHelper);
scene.add(group);

return scene;
}
Insert cell
camera = {
const fov = 75;
const aspect = width / height;
const near = 1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.z = 3;
return camera;
}
Insert cell
renderer = {
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(width, height);
return renderer;
}
Insert cell
THREE = {
const THREE = window.THREE = await require("three@0.130.0/build/three.min.js");
await require("three@0.130.0/examples/js/controls/OrbitControls.js").catch(() => {});
return THREE;
}
Insert cell
import { bannerImage } from "@observablehq/banner"
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