MCPcopy Create free account
hub / github.com/collidingScopes/iron-interface / createFlower

Function createFlower

geometry.js:301–362  ·  view source on GitHub ↗
(i, count)

Source from the content-addressed store, hash-verified

299}
300
301function createFlower(i, count) {
302 // Flower/Dandelion parameters
303 const numPetals = 12; // Number of petals
304 const petalLength = 25; // Length of petals
305 const centerRadius = 10; // Radius of center sphere
306 const petalWidth = 0.3; // Width of petals (0-1)
307 const petalCurve = 0.6; // How much petals curve outward (0-1)
308
309 // Calculate whether this particle is in the center or on a petal
310 const centerParticleCount = Math.floor(count * 0.3); // 30% of particles in center
311 const isCenter = i < centerParticleCount;
312
313 if (isCenter) {
314 // Center particles form a sphere
315 const t = i / centerParticleCount;
316 const phi = Math.acos(2 * t - 1);
317 const theta = 2 * Math.PI * i * (1 + Math.sqrt(5)); // Golden ratio distribution
318
319 // Create a sphere for the center
320 return new THREE.Vector3(
321 Math.sin(phi) * Math.cos(theta) * centerRadius,
322 Math.sin(phi) * Math.sin(theta) * centerRadius,
323 Math.cos(phi) * centerRadius
324 );
325 } else {
326 // Petal particles
327 const petalParticleCount = count - centerParticleCount;
328 const petalIndex = i - centerParticleCount;
329
330 // Determine which petal this particle belongs to
331 const petalId = petalIndex % numPetals;
332 const positionInPetal = Math.floor(petalIndex / numPetals) / Math.floor(petalParticleCount / numPetals);
333
334 // Calculate angle of this petal
335 const petalAngle = (petalId / numPetals) * Math.PI * 2;
336
337 // Calculate radial distance from center
338 // Use a curve so particles are denser at tip and base
339 const radialT = Math.pow(positionInPetal, 0.7); // Adjust density along petal
340 const radialDist = centerRadius + (petalLength * radialT);
341
342 // Calculate width displacement (thicker at base, thinner at tip)
343 const widthFactor = petalWidth * (1 - radialT * 0.7);
344 const randomWidth = (Math.random() * 2 - 1) * widthFactor * petalLength;
345
346 // Calculate curve displacement (petals curve outward)
347 const curveFactor = petalCurve * Math.sin(positionInPetal * Math.PI);
348
349 // Convert to Cartesian coordinates
350 // Main direction follows the petal angle
351 const x = Math.cos(petalAngle) * radialDist +
352 Math.cos(petalAngle + Math.PI/2) * randomWidth;
353
354 const y = Math.sin(petalAngle) * radialDist +
355 Math.sin(petalAngle + Math.PI/2) * randomWidth;
356
357 // Z coordinate creates the upward curve of petals
358 const z = curveFactor * petalLength * (1 - Math.cos(positionInPetal * Math.PI));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected