Performant Particles tsParticles or Particles.js System In JavaScript | perParticles.js

Particle Performance is a demo that has been written to handle a relatively large amount of particles without slowing down to the same degree as the current solutions.

Since it was meant to be a proof of concept rather than a ready-to-use solution, it cannot be imported as a package, but should still be user-friendly. All the customization options are listed at the top of the perParticles.js file and are quite self-explanatory.

particle js, particles js background, particles js examples, particles js alternative, javascript particle system, particles js cdn

A Lightweight and Powerful Particle Animation Javascript Library | Proton.js

How to make use of it:

1. Enter perParticles.css and perParticles.js into the document.

<link rel="stylesheet" href="perParticles.css" />
<script src="perParticles.js"></script>

2. Create an HTML canvas element for the particle system.

<canvas></canvas>

3. It generates particles on the canvas.

// updateDaemon.js
const createNode = options => {
  const {
    minNodeSize,
    maxNodeSize,
    minVelocity,
    maxVelocity,
    width,
    height
  } = options;
  const nodeX = Math.floor(Math.random() * (width + 100) - 50);
  const nodeY = Math.floor(Math.random() * (height + 100) - 50);
  const nodeVelocityX = (Math.random() * maxVelocity + minVelocity) * (Math.round(Math.random()) ? 1 : -1);
  const nodeVelocityY = (Math.random() * maxVelocity + minVelocity) * (Math.round(Math.random()) ? 1 : -1);
  const nodeRadius = Math.floor(Math.random() * maxNodeSize + minNodeSize);
  return { x: nodeX, y: nodeY, r: nodeRadius, vx: nodeVelocityX, vy: nodeVelocityY };
};
self.addEventListener('message', e => {
  const { command, nodes, options } = e.data;
  switch (command) {
    case 'update':
      const { nodesAmount, maxVelocity, minVelocity, width, height } = options;
      while (nodes.length < nodesAmount) {
        nodes.push(createNode(options));
      }
      if (nodes.length > nodesAmount) {
        nodes.length = nodesAmount;
      }
      for (let i = 0; i < nodes.length; i++) {
        nodes[i].x += nodes[i].vx;
        nodes[i].y += nodes[i].vy;
        if ((nodes[i].x < -25 || nodes[i].x > width + 25) || (nodes[i].y < -25 || nodes[i].y > height + 25)) {
          nodes[i].vx = (Math.random() * maxVelocity + minVelocity) * (nodes[i].vx < 0 ? 1 : -1);
          nodes[i].vy = (Math.random() * maxVelocity + minVelocity) * (nodes[i].vy < 0 ? 1 : -1);
        }
      }
      const buckets = [];
      const numberOfBuckets = 5;
      const bucketWidth = Math.ceil(width / numberOfBuckets);
      for (let i = 0; i < numberOfBuckets; i++) {
        buckets.push({ x: i * bucketWidth - 50, y: -25, w: bucketWidth + 100, h: height + 50, nodes: [] });
      }
      nodes.forEach((node) => {
        buckets.forEach((bucket) => {
          if (node.x >= bucket.x && node.x <= bucket.x + bucket.w && node.y >= bucket.y && node.y <= bucket.y + bucket.h) {
            bucket.nodes.push(node);
          }
        });
      });
      self.postMessage({ nodes, buckets });
      break;
    case 'stop':
      self.close();
      break;
  };
});
// bucketDaemon.js
const getDistance = (node1, node2) => {
  const distanceX = Math.abs(node1.x - node2.x);
  const distanceY = Math.abs(node1.y - node2.y);
  return Math.sqrt(distanceX ** 2 + distanceY ** 2);
};
self.addEventListener('message', e => {
  const { command, bucket } = e.data;
  switch (command) {
    case 'process':
      const lines = [];
      bucket.nodes.forEach((node, i) => {
        bucket.nodes.slice(i + 1).forEach(n => {
          const distance = getDistance(node, n);
          if (distance < 150) {
            lines.push({ n1: node, n2: n, distance });
          }
        });
      });
      self.postMessage({ lines });
      break;
    case 'stop':
      self.close();
      break;
  };
});

4. Allocate the particles by overriding the parameters at the beginning of perParticles.js.

let minNodeSize = 1;
let maxNodeSize = 3;
let minVelocity = 0.25;
let maxVelocity = 2;
let nodesAmount = 1000;
let backgroundColor = '#222222';
let nodeColor = '#D1C4E9';
let lineColor = '#CE93D8';

High Performance Particle System In JavaScript, perParticles Plugin/Github


See Demo And Download

 

Official Website(Alaricus): Click Here

This superior jQuery/javascript plugin is developed by Alaricus. For extra Advanced Usages, please go to the official website.

Related Posts

jquery-fancy-file-uploader

Convert An HTML File Input Type Into a Fancy File Uploader

jQuery Fancy File Uploader is a jQuery extension for converting an HTML file input type into a portable fancy file uploader. Choose from an MIT or LGPL…

Input-Values-Using-Mouse-Drag

Create Side Sliders Input Values Using Mouse Drag | Pointer Lock

HTML Range Slider is a lightweight library to create side sliders to adjust values easily and precisely by making use of the Pointer Lock API. Side Slider…

simple-parallax-scrolling-js

Smooth and Lightweight Parallax Scroll Library in Pure Javascript

Lightweight and seamless parallax scrolling library implemented in pure javascript using hardware acceleration for additional performance. Main Features Extremely lightweight with no dependencies A few kilobytes of pure…

Convert-Form-Data-to-JSON

How to Convert Form Data to JSON with HTML Forms | FormsJS

FormsJS is a simple-to-use JavaScript library that covers type subject values to JSON in real time. The items containing the data category will be analyzed automatically. It…

editable-html-table-using-javascript

A Small jQuery Extension to Convert An Editable HTML Table

Editable Table is a small jQuery extension to convert an editable HTML table for fast data entry and validation. A small jQuery extension to convert a static…

jquery.youtube-background

Simple jQuery Plugin for Embedding YouTube Videos As Cover Background

jquery.youtube-background is a jQuery plugin built to facilitate YouTube embeds as cover wallpaper using the YouTube Embed API. There is another jQuery Youtube Video Background plugin that…