@midpoint68/pocket
v1.0.4
Published
A simple and efficient particle manager for JavaScript.
Downloads
12
Maintainers
Readme
An efficient and scalable method of managing particle systems.
Creating a Pocket
var pocket = new Pocket();
Adding Particles to a Pocket
// Add 1000 particles with random locations within the bounds (0, 0, 0) and (100, 100, 100)
for(let i = 0; i < 1000; i++){
pocket.put({
data: 'Particle #'+i,
x: Math.random()*100,
y: Math.random()*100,
z: Math.random()*100,
radius: 0.5
});
}
Searching for Particles
// Get a Set of all particles within a 1 unit radius of the point (50, 50, 50)
const particles = pocket.search(1, {x: 50, y: 50, z: 50});
Getting the Closest Particle
// Get only the closest particle to the point (50, 50, 50)
const closest = pocket.closest({x: 50, y: 50, z: 50});
Moving a Particle
// Get the closest particle to (50, 50, 50) and move it to (0, 0, 0)
const closest = pocket.closest({x: 50, y: 50, z: 50});
closest.moveTo({x: 0, y: 0, z: 0});