Project

General

Profile

Actions

Improvement #1412

closed

Improve spawning algorithm to spawn in all board instead of circle

Added by Axel "Elanis" Soupé over 2 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
Start date:
03/15/2022
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

Test:

function calcNextLayer() {
	prevLayer++;

	const layerMaxItemsPerLine = (-1 + prevLayer * 4);
	const layerMaxItemsPerColumn = (-1 + prevLayer * 2);

/*
	f(1) = (1/1)
	f(2) = (5/3)
	f(3) = (9/5)
	f(4) = (13/7)
	f(5) = (17/9)
*/

	const newPoints = [];
	for(let itemX = 0; itemX < layerMaxItemsPerLine; itemX++) {
		for(let itemY = 0; itemY < layerMaxItemsPerColumn; itemY++) {
			let x = (-0.5 * layerMaxItemsPerLine + itemX + 0.5) * itemsFinalDistance + itemsFinalDistance / 2;
			let y = (-0.5 * layerMaxItemsPerColumn + itemY + 0.5) * itemsFinalDistance + itemsFinalDistance / 2;

			if(!positions.find(p => p.x === x && p.y === y)) {
				newPoints.push({ x, y });
			}

			/*if(itemY === 0 || itemY === (layerMaxItemsPerColumn - 1) || itemX === 0 || itemX === (layerMaxItemsPerLine - 1)) {
				newPoints.push({
					x: (-0.5 * layerMaxItemsPerLine + itemX + 0.5) * itemsFinalDistance,
					y: (-0.5 * layerMaxItemsPerColumn + itemY + 0.5) * itemsFinalDistance,
				});
			}*/
		}
	}

	positions = [...positions, ...newPoints];

	console.log(newPoints);

	return newPoints;
}
Actions

Also available in: Atom PDF