npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tsparticles/preset-confetti

v3.0.2

Published

tsParticles confetti preset

Downloads

5,377

Readme

banner

tsParticles Confetti Preset

jsDelivr npmjs npmjs GitHub Sponsors

tsParticles preset for white and red confetti launched from the screen center on a transparent background.

Slack Discord Telegram

tsParticles Product Hunt

Sample

demo

How to use it

CDN / Vanilla JS / jQuery

<script src="https://cdn.jsdelivr.net/npm/@tsparticles/preset-confetti@3/tsparticles.preset.confetti.bundle.min.js"></script>

Usage

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

tsParticles.load({
  id: "tsparticles",
  options: {
    preset: "confetti",
  },
});

Customization

tsParticles.load({
  id: "tsparticles",
  options: {
    particles: {
      color: {
        value: ["#0000ff", "#00ff00"],
      },
    },
    preset: "confetti",
  },
});

Like in the sample above, the white and red colors will be replaced by blue and lime.

Cannons

The preset has a single life cannon, with a short duration. The effect is immediate and ends few seconds after, but this can be customized too.

The confetti cannons are made using the Emitter plugin, which is already documented here.

These are the default cannon (emitter) options:

The default emitter options are these:

{
  "startCount": 50,
  "position": {
    "x": 50,
    "y": 50
  },
  "size": {
    "width": 0,
    "height": 0
  },
  "rate": {
    "delay": 0,
    "quantity": 0
  },
  "life": {
    "duration": 0.1,
    "count": 1
  }
}

Let's see how to create the most common types of cannon animations:

Long lasting Cannon

To create a long-lasting cannon, the emitter life options need some changes.

The life.duration needs to be increased, the value is in seconds, so actually it lasts one tenth of a second.

If life.duration is set to 0, the cannon will last forever.

The life.count parameter instead can be changed as well, but the animation will last for the specified duration, life.count times, if the life.duration is set to 0, the life.count is ignored since its first life will last forever.

Sample
tsParticles.load({
  id: "tsparticles",
  options: {
    emitters: {
      life: {
        duration: 0,
      },
    },
    preset: "confetti",
  },
});

This will create an infinite cannon shooting confetti from the center of the canvas.

Immortal Cannon - Fireworks

To create a fireworks effect, or an immortal cannon, the emitter life options, again, need some changes.

The life.duration can be kept to the default short value, but the life.count is what we need to change.

For an immortal cannon we can change life.count to 0 and the emitter will continue respawning every life.delay seconds. Actually is not specified, if you want some delay between "explosions", set this value to something greater than 0.

For an improved effect, the position as well can be customized. For randomizing it, it can be set to {}, and it'll have a random position every "explosion". If a coordinate is set, that will be used everytime, as a percentage of the canvas size.

tsParticles.load({
  id: "tsparticles",
  options: {
    emitters: {
      life: {
        count: 0,
      },
      position: {
        // uncomment only one of these lines,
        // to have explosions on the x or y axis
        // centered on the other one
        // if everything is kept commented,
        // random positions will be used everytime the cannon fires
        // x: 50,
        // y: 50
      },
    },
    preset: "confetti",
  },
});
Multiple Cannons

Now that we have played with a single cannon, what about multiple ones?

This needs more customization since the cannons array will overwrite the existing options.

First let's start overriding the emitters (cannons) options placing an array instead of an object.

Like this:

tsParticles.load({
  id: "tsparticles",
  options: {
    emitters: [],
    preset: "confetti",
  },
});

If you test this, you won't see anything, because the emitters are set to an empty array, so there's nothing to show.

Now you can add emitters to the array, using the standard tsParticles emitters options.

Sample
tsParticles.load({
  id: "tsparticles",
  options: {
    emitters: [
      {
        life: {
          duration: 5,
          count: 1,
        },
        position: {
          x: 0,
          y: 30,
        },
        particles: {
          move: {
            direction: "top-right",
          },
        },
      },
      {
        life: {
          duration: 5,
          count: 1,
        },
        position: {
          x: 100,
          y: 30,
        },
        particles: {
          move: {
            direction: "top-left",
          },
        },
      },
    ],
    preset: "confetti",
  },
});

This samples creates two cannons, one on the left and one on the right of the canvas, at 30% of canvas height, shooting in opposite directions.

Frameworks with a tsParticles component library

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

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


flowchart TD

subgraph b [Bundles]
bb[tsParticles Basic]
end

subgraph pl [Plugins]
ple[Emitters]
plm[Motion]
end

bb --> pl

subgraph s [Shapes]
ssq[Square]
end

bb --> s

subgraph u [Updaters]
ul[Life]
urol[Roll]
urot[Rotate]
uti[Tilt]
uw[Wobble]
end

bb --> u

subgraph pr [Presets]
prc[Confetti]
end

bb & ple & plm & ssq & ul & urol & urot & uti & uw --> prc