Published
Edited
Sep 19, 2020
12 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
THREE = require("three") // Load three.js library
Insert cell
Insert cell
sceneObject = {
const scene = new THREE.Scene(); // Create scene
scene.background = new THREE.Color('black'); // Sets scene background color
return scene;
}
Insert cell
Insert cell
cube={
const material = new THREE.MeshNormalMaterial();
const geometry = new THREE.BoxGeometry(1,1,1);
return new THREE.Mesh(geometry,material);
}
Insert cell
torous = {
const material = new THREE.MeshNormalMaterial(); // Creates a basic mesh Material
const geometry = new THREE.TorusGeometry(10, 3, 16, 100); // Create box of size 1
return new THREE.Mesh(geometry, material); // Create mesh from geometry and material
}
Insert cell
sceneObject.add(torous)// Add the cube to the scene
Insert cell
sceneObject.add(cube)
Insert cell
Insert cell
Insert cell
Insert cell
import {slider, color} from "@jashkenas/inputs"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
camera = {
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); // Create camera
camera.position.z = 20; // Place the camera at (0,0,3)
return camera;
}
Insert cell
Insert cell
renderer = {
const renderer = new THREE.WebGLRenderer({antialias: true}); // Create renderer
renderer.setSize(width, 500); // Set the size of the renderer
renderer.render(sceneObject, camera); // Add the scene and camera to the renderer
yield renderer.domElement;
}
Insert cell
Insert cell
rendererRotation = {
const renderer = new THREE.WebGLRenderer({antialias: true}); // Create renderer
renderer.setSize(width, 500); // Set the size of the renderer
while (true) { // Code that runs every frame
torous.rotation.x += .02; // Rotate cube by 0.01 in x every frame
torous.rotation.y += .02; // Rotate cube by 0.01 in y every frame
cube.rotation.x += .01; // Rotate cube by 0.01 in x every frame
cube.rotation.y += .01; // Rotate cube by 0.01 in y every frame
renderer.render(sceneObject, camera); // Add the scene and camera to the renderer
yield renderer.domElement;
}
}
Insert cell
Insert cell
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