Published
Edited
May 18, 2019
1 fork
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
THREE = require("three") // Load three.js library
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene(); // Create scene
scene.background = new THREE.Color('#ffffff'); // Modify scene background color
return scene;
}
Insert cell
Insert cell
Insert cell
cube = {
const material = new THREE.MeshNormalMaterial(); // Create Normal Material
const geometry = new THREE.BoxGeometry(1,1,1); // Create box of size 1
return new THREE.Mesh(geometry, material); // Create mesh from geometry and material
}

Insert cell
scene.add(cube) // Add the cube to the scene
Insert cell
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 = 3; // 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
while (true) { // Code that runs every frame
cube.rotation.x += rotation; // Rotate cube by 0.01 in x every frame
cube.rotation.y += rotation; // Rotate cube by 0.01 in y every frame
renderer.render(scene, camera); // Add the scene and camera to the renderer
yield renderer.domElement;
}
}
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