Platform
Solutions
Resources
Pricing
Sign in
Sign up
Colin Reid
Data Viz / Photography / Generative Art
Workspace
Fork
Published
By
Colin Reid
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
THREE
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scene
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cube
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fov
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
aspect
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
near
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
far
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
camera
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
renderer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rotation
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML