Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sienki-jenki/668c14e5e36e6e1546aad95fdbcf66b2 to your computer and use it in GitHub Desktop.
Save sienki-jenki/668c14e5e36e6e1546aad95fdbcf66b2 to your computer and use it in GitHub Desktop.
function calculateDensityInCell() {
for (let i = 0; i < N * (1 / squareSize); i++) {
let tempArr = [];
for (let j = 0; j < N * (1 / squareSize); j++) {
let particlesInCell = particlesArr.filter(particle => {
if (((particle.x > (-N / 2) + j * squareSize) && (particle.x < (-N / 2) + squareSize + j * squareSize)) &&
((particle.y < (N / 2) - i * squareSize) && (particle.y > (N / 2) - squareSize - i * squareSize))) {
return true;
}
});
tempArr = [...tempArr, particlesInCell.length / Math.pow(squareSize, 2)];
}
cellsDensity = [...cellsDensity, tempArr];
}
console.log(cellsDensity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment