Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body {
  margin: 0;
  overflow: hidden;
}
              
            
!

JS

              
                console.clear();

// Create an empty, needed for the renderer
const scene = new THREE.Scene();
// Create a camera and translate it
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 1, 1.5);

// Create a WebGL renderer and enable the antialias effect
const renderer = new THREE.WebGLRenderer({ antialias: true });
// Define the size and append the <canvas> in our document
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// Add OrbitControls to allow the user to move in the scene
const controls = new THREE.OrbitControls(camera, renderer.domElement);

const group = new THREE.Group();
scene.add(group);

// Create a cube with basic geometry & material
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
  color: 0x66ccff,
  wireframe: true
});
const cube = new THREE.Mesh(geometry, material);
group.add(cube);

// Instantiate a sampler so we can use it later
const sampler = new THREE.MeshSurfaceSampler(cube).build();

// Define the basic geometry of the spheres
const sphereGeometry = new THREE.SphereGeometry(0.05, 6, 6);
// Define the basic material of the spheres
const sphereMaterial = new THREE.MeshBasicMaterial({
  color: 0xffa0e6
});
const spheres = new THREE.InstancedMesh(sphereGeometry, sphereMaterial, 300);
group.add(spheres);

// Create a dummy Vector to store the sampled coordinates
const tempPosition = new THREE.Vector3();
// Create a dummy 3D object to generate the Matrix of each sphere
const tempObject = new THREE.Object3D();
// Loop as many spheres we have
for (let i = 0; i < 300; i++) {
  // Sample a random point on the surface of the cube
  sampler.sample(tempPosition);
  // Store that point coordinates in the dummy object
  tempObject.position.set(tempPosition.x, tempPosition.y, tempPosition.z);
  // Define a random scale
  tempObject.scale.setScalar(Math.random() * 0.5 + 0.5);
  // Update the matrix of the object
  tempObject.updateMatrix();
  // Insert the object udpated matrix into our InstancedMesh Matrix
  spheres.setMatrixAt(i, tempObject.matrix);
}

/// Render the scene on each frame
function render () {  
  // Rotate the cube a little on each frame
  group.rotation.y += 0.01;
  
  renderer.render(scene, camera);
}
renderer.setAnimationLoop(render);

function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', onWindowResize);
              
            
!
999px

Console