tsParticles can be extended with plugins, custom shapes, and custom presets.
This page provides a practical flow to build extensions that users can reuse easily.
tsParticles.load(...)Register a shape with tsParticles.addShape(name, drawer).
tsParticles.addShape("spiral", (context, particle, radius) => {
const data = particle.shapeData as { innerRadius: number; lineSpacing: number };
const realWidth = (radius - data.innerRadius) / data.lineSpacing;
for (let i = 0; i < realWidth * 10; i++) {
const angle = 0.1 * i;
const factor = data.innerRadius + data.lineSpacing * angle;
context.lineTo(factor * Math.cos(angle), factor * Math.sin(angle));
}
});
IShapeDrawer)class SpiralDrawer {
draw(context, particle, radius) {
const data = particle.shapeData;
const realWidth = (radius - data.innerRadius) / data.lineSpacing;
for (let i = 0; i < realWidth * 10; i++) {
const angle = 0.1 * i;
const factor = data.innerRadius + data.lineSpacing * angle;
context.lineTo(factor * Math.cos(angle), factor * Math.sin(angle));
}
}
}
tsParticles.addShape("spiral", new SpiralDrawer());
Useful interface: IShapeDrawer
{
"particles": {
"shape": {
"type": "spiral",
"options": {
"spiral": {
"innerRadius": 1,
"lineSpacing": 1,
"close": false,
"fill": false
}
}
}
}
}
Register a preset with tsParticles.addPreset(name, options) and then use it in config with preset.
tsParticles.addPreset("my-fire", {
fpsLimit: 40,
particles: {
number: {
value: 80,
},
move: {
enable: true,
speed: 6,
},
color: {
value: ["#fdcf58", "#757676", "#f27d0c", "#800909", "#f07f13"],
},
},
background: {
image: "radial-gradient(#4a0000, #000)",
},
});
Preset usage:
{
"preset": "my-fire"
}
tsparticles-shape tagtsparticles-preset tag@tsparticles/configs if you need a concrete object to evolve into a preset