Created
April 5, 2020 20:41
-
-
Save sienki-jenki/668c14e5e36e6e1546aad95fdbcf66b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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