Skip to content

Instantly share code, notes, and snippets.

@Mamboleoo
Last active February 6, 2019 10:57
Show Gist options
  • Save Mamboleoo/c35cd80fba3fb8cbe60fe80c132dd9ee to your computer and use it in GitHub Desktop.
Save Mamboleoo/c35cd80fba3fb8cbe60fe80c132dd9ee to your computer and use it in GitHub Desktop.
Sort particles [2D-3D]
function render(a) {
...
// Loop through the dots array and project every dot
for (let i = 0; i < dots.length; i++) {
dots[i].project();
}
// Sort dots array based on their projected size
dots.sort((dot1, dot2) => {
return dot1.sizeProjection - dot2.sizeProjection;
});
// Loop through the dots array and draw every dot
for (let i = 0; i < dots.length; i++) {
dots[i].draw();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment