npm.io
4.4.0 • Published 1 week ago

@tsparticles/preset-stars

Licence
MIT
Version
4.4.0
Deps
2
Size
550 kB
Vulns
0
Weekly
0
Stars
9.0K

banner

tsParticles Stars Preset

jsDelivr npmjs npmjs GitHub Sponsors

tsParticles preset for creating a starry night effect with blinking stars.

Discord Telegram

tsParticles Product Hunt

Sample

demo

Quick checklist

  1. Install @tsparticles/engine (or use the CDN bundle below)
  2. Call loadStarsPreset(tsParticles) before tsParticles.load(...)
  3. Set preset: "stars" in options

How to use it

CDN / Vanilla JS / jQuery
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/preset-stars@4/tsparticles.preset.stars.bundle.min.js"></script>
Usage

Once the scripts are loaded you can set up tsParticles like this:

(async () => {
  await loadStarsPreset(tsParticles);

  await tsParticles.load({
    id: "tsparticles",
    options: {
      preset: "stars",
    },
  });
})();
Customization

Important You can override all the options defining the properties like in any standard tsParticles installation.

tsParticles.load({
  id: "tsparticles",
  options: {
    particles: {
      shape: {
        type: "square", // starting from v2, this require the square shape script
      },
    },
    preset: "stars",
  },
});

Like in the sample above, the circles will be replaced by squares.

Frameworks with a tsParticles component library

Checkout the documentation in the component library repository and call the loadStarsPreset function instead of loadFull, loadSlim or similar functions.

The options shown above are valid for all the component libraries.

Dependencies

This preset loads and combines the following packages:

Package Role in this preset README
@tsparticles/basic Base runtime bundle used by the preset https://www.npmjs.com/package/@tsparticles/basic
@tsparticles/engine tsParticles engine and preset registration https://www.npmjs.com/package/@tsparticles/engine

If you want to customize one specific behavior, start from the related package README above.

Common pitfalls

  • Calling tsParticles.load(...) before loadStarsPreset(tsParticles)
  • Changing particle shape without loading the corresponding shape package
  • The stars preset uses a dark background by default; override background.color if you need a different style

flowchart TD

subgraph b [Bundles]
bb[tsParticles Basic]
end

subgraph pr [Presets]
prst[Stars]
end

bb --> prst

Keywords