If you are the kind of web design professional who keeps a bookmarks folder filled with examples of stylish layouts and impressive effects, chances are you have seen HTML Canvas projects featuring a field of particles that respond to the motion of the mouse pointer or the direction of touchscreen gestures. Depending on the vibe that the website wishes to convey, the particle effect may resemble a field of stars from an old video game or a bunch of confetti suspended in the air.
Digital agencies, blockchain development firms, and nightclubs are the kind of businesses that would implement such an effect on their home pages. Even though HTML Canvas can be used to make these effects more attractive, they are mostly JavaScript, and quite a few libraries are available to this effect. The oldest libraries can be found on GitHub under the names Particle.JS, Particles.JS, and tsParticles.JS.
While you could always use the Three.JS framework to call up the aforementioned particle effect libraries, there is no real need to do so; in fact, this would be overkill because of the considerable RAM consumption. The "best" solution would be to build a particle generator from scratch that allows you to build a custom-made effect on your own.
Since each individual particle can be drawn with JavaScript, there is no particular limitation on the shape and nature of the particle. In this article, we will be looking at a few options for building your own particle effect generator, and we will be looking at methodologies to do so.
Creating the Basics of the Particle Effect
Before you go any further with your particle effect generator, you need to set the stage with some of the basics of the effect. For starters, you have the following properties that must be set before a particle effect can be constructed:
The position of the particle
The velocity of the particle
The radius of the particle
The initial position of the particle, where it appears on screen
The number of particles
The initial position of each particle
The direction and length of each particle
The distance of each particle from the center of the canvas
The speed at which each particle would travel
The number of times each particle is generated
These properties are the basics, which you can determine and create within JavaScript. It is important to understand that, while these properties may seem straightforward, they can be quite complex in actuality. For example, if we are generating 10,000 particles at a distance of 5,000, each particle will only last for 3,000 frames. If each frame takes 0.5 seconds to process, it would only take a maximum of 18,000 seconds (5,000 x 3,000 x 0.5) to generate 10,000 particles at a distance of 5,000. This is obviously not the most efficient way to accomplish this, which is why you would be better off with the Particle.JS library. For more information click here https://v.redd.it/mxr8u3i308971.