Create custom particles
Use createParticle() to create particles at specific locations with custom
directions, speeds and sizes.
Syntax:
createParticle(posX, posY, dir, speed, size)
JavaScript
const scp = new CanvasParticles('#showcase-create-particles', {
mouse: {
interactionType: 1, // Don't actually move the particles
connectDistMult: 150,
distRatio: 1,
},
particles: {
drawLines: false, // For performance in this case
connectDistance: 1,
rotationSpeed: 0, // Very important!
},
}).start()
const createParticleSineWaves = () => {
scp.resizeCanvas()
scp.newParticles({ keepAuto: true, keepManual: false })
const w = scp.canvas.width - scp.offX * 2
for (let x = 0; x < w; x += 0.5) {
const y1 = Math.sin(x / 50) * 50
const y2 = Math.cos(x / (w / 50)) * 50 + 250
scp.createParticle(x + y1, y1 * 3, 0, 1, 2)
scp.createParticle(x, y2, Math.PI / 2, 1, 3)
}
}
createParticleSineWaves()
window.addEventListener('resize', createParticleSineWaves)