Pen Settings



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


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


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.


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.




                body {
  margin: 0;
  overflow: hidden;



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

// 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);

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

const group = new THREE.Group();

// Create a torus know with basic geometry & material
const geometry = new THREE.TorusKnotGeometry(4, 1.3, 100, 16);
const torusKnot = new THREE.Mesh(geometry);

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

// Array used to store all points coordinates
const vertices = [];
// Create a dummy Vector to store the sampled coordinates
const tempPosition = new THREE.Vector3();
// Loop to sample a coordinate for each points
for (let i = 0; i < 15000; i ++) {
  // Sample a random position in the torus
  // Push the coordinates of the sampled coordinates into the array
	vertices.push(tempPosition.x, tempPosition.y, tempPosition.z);

// Create a geometry for the points
const pointsGeometry = new THREE.BufferGeometry();
// Define all points positions from the previously created array
pointsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
// Define the matrial of the points
const pointsMaterial = new THREE.PointsMaterial({
  color: 0xff61d5,
  size: 0.03
// Create an instance of points based on the geometry & material
const points = new THREE.Points(pointsGeometry, pointsMaterial);
// Add them into the main group

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

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