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

Function createGrid

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

Source from the content-addressed store, hash-verified

1// --- PATTERN FUNCTIONS ---
2function createGrid(i, count) {
3 const sideLength = Math.ceil(Math.cbrt(count));
4 const spacing = 60 / sideLength;
5 const halfGrid = (sideLength - 1) * spacing / 2;
6
7 // Determine which side of the cube this particle should be on
8 const totalSides = 6; // A cube has 6 sides
9 const pointsPerSide = Math.floor(count / totalSides);
10 const side = Math.floor(i / pointsPerSide);
11 const indexOnSide = i % pointsPerSide;
12
13 // Calculate a grid position on a 2D plane
14 const sideLength2D = Math.ceil(Math.sqrt(pointsPerSide));
15 const ix = indexOnSide % sideLength2D;
16 const iy = Math.floor(indexOnSide / sideLength2D);
17
18 // Map to relative coordinates (0 to 1)
19 const rx = ix / (sideLength2D - 1 || 1);
20 const ry = iy / (sideLength2D - 1 || 1);
21
22 // Convert to actual coordinates with proper spacing (-halfGrid to +halfGrid)
23 const x = rx * spacing * (sideLength - 1) - halfGrid;
24 const y = ry * spacing * (sideLength - 1) - halfGrid;
25
26 // Place on the appropriate face of the cube
27 switch(side % totalSides) {
28 case 0: return new THREE.Vector3(x, y, halfGrid); // Front face
29 case 1: return new THREE.Vector3(x, y, -halfGrid); // Back face
30 case 2: return new THREE.Vector3(x, halfGrid, y); // Top face
31 case 3: return new THREE.Vector3(x, -halfGrid, y); // Bottom face
32 case 4: return new THREE.Vector3(halfGrid, x, y); // Right face
33 case 5: return new THREE.Vector3(-halfGrid, x, y); // Left face
34 default: return new THREE.Vector3(0, 0, 0);
35 }
36}
37
38function createSphere(i, count) {
39 // Sphere distribution using spherical coordinates for surface only

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected