Here we build snowflake fractals based on spheres rather than convex polyhedra as on the previous page. Whereas a polyhedron has a fixed set of vertices at which to place scaled-down copies, a sphere invites placement of copies at any point on the surface. Accordingly, to build a level fractal, we place nbrPoints many level fractals at random points on the sphere.
The following function is similar to function makePolyhedralSnowflake
on the previous page. The main difference is that whereas the previous program translates scaled-down fractals to the vertices of the current polyhedron, the following function translates them to random points on the current sphere.1
function makeSphereSnowflake(level, scale, geom, nbrPoints, involute) { let sphere = new THREE.Mesh(geom, materials[level]); if (level > 0) { let root = new THREE.Object3D(); sphere.add(root); root.scale.set(scale, scale, scale); let tf; if (!involute) tf = (sphereRadius * (1 + scale)) / scale; else tf = (sphereRadius * (1 - scale)) / scale; for (let i = 0; i < nbrPoints; i++) { let root2 = new THREE.Object3D(); let v = getRandomPointOnSphere(sphereRadius); let v2 = v.clone().multiplyScalar(tf); root2.position.set(v2.x, v2.y, v2.z); root2.add(makeSphereSnowflake(level-1, scale, geom, nbrPoints, involute)); root.add(root2); } } return sphere; }
- Here geom is the shared sphere geometry whose radius is given by the global variable sphereRadius. ↩