Skip to content

Instantly share code, notes, and snippets.

@KhanMaytok
Created December 8, 2015 23:38
Show Gist options
  • Save KhanMaytok/d76f58c55704b7ce6140 to your computer and use it in GitHub Desktop.
Save KhanMaytok/d76f58c55704b7ce6140 to your computer and use it in GitHub Desktop.
Create a sphere made of particles with Three.js
var distance = 100;
var geometry = new THREE.Geometry();
for (var i = 0; i < 1000; i++) {
var vertex = new THREE.Vector3();
var theta = THREE.Math.randFloatSpread(360);
var phi = THREE.Math.randFloatSpread(360);
vertex.x = distance * Math.sin(theta) * Math.cos(phi);
vertex.y = distance * Math.sin(theta) * Math.sin(phi);
vertex.z = distance * Math.cos(theta);
geometry.vertices.push(vertex);
}
var particles = new THREE.PointCloud(geometry, new THREE.PointCloudMaterial({
color: 0xffffff
}));
particles.boundingSphere = 50;
scene.add(particles);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment