diff --git a/index.html b/index.html
index 2a86aed..f6d9909 100644
--- a/index.html
+++ b/index.html
@@ -283,7 +283,7 @@ if scale < 1:
-
+
diff --git a/script.js b/script.js
index 9b021b7..b4c8ee9 100644
--- a/script.js
+++ b/script.js
@@ -516,8 +516,8 @@ preset16OctBtn.addEventListener('click', () => {
generateInputsBtn.addEventListener('click', () => {
const count = parseInt(moduleCountInput.value);
- if (isNaN(count) || count < 2) {
- alert('Please enter a valid number of modules above or equal to 2.');
+ if (isNaN(count) || count < 2 || count > 64) {
+ alert('Please enter a valid number of modules between 2 and 64.');
return;
}
generateModuleInputs(count);
@@ -557,11 +557,67 @@ applyCustomBtn.addEventListener('click', () => {
* BEGIN DYNAMIC DOM FUNCTIONS
*/
+// Function to calculate evenly spaced module positions in circular layers
+function calculateModulePositions(count) {
+ if (count <= 0) return [];
+
+ const baseRadius = 50; // Base radius for the first layer
+ const positions = [];
+ let remainingModules = count;
+ let numberOfLayers = Math.ceil(count / 6);
+ let modulesPerLayer = Math.ceil(count / numberOfLayers);
+ let angleOffset = 0;
+ let currentLayer = 0;
+ let moduleIndex = 0;
+
+ while (remainingModules > 0) {
+ // Determine modules for this layer
+ let modulesInThisLayer;
+
+ if (remainingModules <= modulesPerLayer) {
+ // Last layer gets all remaining modules
+ modulesInThisLayer = remainingModules;
+ } else {
+ // All other layers: try to distribute evenly with max modulesPerLayer
+ const remainingLayers = Math.ceil(remainingModules / modulesPerLayer);
+ modulesInThisLayer = Math.min(modulesPerLayer, Math.ceil(remainingModules / remainingLayers));
+ }
+
+ // Calculate radius for this layer
+ const radius = currentLayer === 0 ? baseRadius : baseRadius * (1 + currentLayer * 0.75);
+
+ // Calculate positions for modules in this layer
+ for (let i = 0; i < modulesInThisLayer; i++) {
+ const angle = (angleOffset + 2 * Math.PI * i) / modulesInThisLayer;
+ const x = Math.round(radius * Math.cos(angle));
+ const y = Math.round(radius * Math.sin(angle));
+
+ positions.push({
+ x: x,
+ y: y,
+ name: `Layer ${currentLayer + 1} Module ${(moduleIndex % modulesPerLayer) + 1}`
+ });
+
+ moduleIndex++;
+ }
+ angleOffset += Math.PI;
+
+ remainingModules -= modulesInThisLayer;
+ currentLayer++;
+ }
+
+ return positions;
+}
+
function generateModuleInputs(count) {
const container = document.getElementById('module-position-inputs');
container.innerHTML = ''; // Clear existing inputs
+ // Calculate evenly spaced positions
+ const positions = calculateModulePositions(count);
+
for (let i = 0; i < count; i++) {
+ const position = positions[i];
const moduleFieldset = document.createElement('fieldset');
moduleFieldset.className = 'module-input-group';
moduleFieldset.innerHTML = `
@@ -569,15 +625,15 @@ function generateModuleInputs(count) {
-
+
-
+
-
+
`;
container.appendChild(moduleFieldset);