Giter VIP home page Giter VIP logo

superparticles's Introduction

SuperParticles

Performance-focused alternative to VincentGarreau's particles.js

Introduction

SuperParticles aims at resolving the major performance issues that come with particles.js, by using WebGL when possible and also by allowing you to limit the frame rate (FPS). If you have more ideas on what could be done to further improve the performance, feel free to open an issue.

GIF Demo

Video

Live Demo

https://t-vk.github.io/SuperParticles/demo.html

How To Use

Jquery is optional, but recommended. Pixi.js is required (preferrably in a version above 5.0.0-rc):

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://pixijs.download/dev-graphics-batch-pool/pixi.js"></script>
<script src="https://cdn.jsdelivr.net/gh/T-vK/SuperParticles@master/SuperParticles.js"></script>
<script>
    window.onload = function(){
        var superParticles = new SuperParticles()
    }
</script>

If you want, you can pass a div container to SuperParticles which then will be used to render the particles:

<body>
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="https://pixijs.download/dev-graphics-batch-pool/pixi.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/T-vK/SuperParticles@master/SuperParticles.js"></script>
    <div id="super-particles"></div>

    <script>
        window.onload = function(){
            var divContainer = '#super-particles'
            new SuperParticles({
                container: divContainer
            })
        }
    </script>
</body>

You can limit the FPS like this:

new SuperParticles({
    maxFps: 30
})

API

new SuperParticles(cfg)

Creates a new SuperParticles instance.

cfg defaults to:

{
    useJquery: undefined, // true/false/undefined
    maxFps: 30, // requires pixi.js v5
    autoStartAnimation: true, // true/false
    container: {
        element: undefined,
        backgroundCssRule: "radial-gradient(ellipse at center, rgba(10,46,56,1) 0%,rgba(34,34,34,1) 70%)" // css or null (null: don't modify container background)
    },
    pixiApp: { // these are documented here: http://pixijs.download/release/docs/PIXI.Application.html#Application
        antialias: true,
        transparent: true,
        forceFXAA: false,
        powerPreference: 'high-performance',
        resolution: 1.0
    },
    particles: {
        amount: 80, // unit: particles
        radius: 2, // unit: pixels
        velocity : 10, // unit: pixels/second
        color: "0xFFFFFF", // unit: rgb hex color
        fadeInDuration: 3000, // unit: milliseconds
        fadeOutDuration: 600, // unit: milliseconds
        keepRelativePositionOnResize: true, // true/false
    },
    lines: {
        minDistance: 0.09, // unit: percent (1: 100%; 0: 0%
        color: "0xFFFFFF", // unit: hex color
        maxOpacity: 0.4, // 1: full opacity; 0: no opacity
        thickness: 1, // unit: pixels
        distanceBasedTransparency: true, // true/false
    },
    debug: {
        showFps: false, // true/false
    }
}

but you can overwrite individual properties if you like.

superParticles.stopAnimation()

Pauses the SuperParticles instance.

superParticles.startAnimation()

Resume the SuperParticles instance.

superParticles.destroy()

Destroys the SuperParticles instance. (If you want to reuse the instance afterwards, you have to call reinit first!)

superParticles.reinit()

Reinitializes the instance. (Useful after destroying it.)

superParticles.cfg

This is the config object of the instance. You can overwrite the cfg object during runtime. E.g. superParticles.cfg = { pixiApp: { antialiasing: true } }
Don't do superParticles.cfg.pixiApp.antialiasing = true

superparticles's People

Contributors

swent avatar t-vk avatar xenoken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

superparticles's Issues

Does it support interactivity?

e.g. like particles.js:

{
  ...

  "interactivity": {
    "detect_on": "canvas",
    "events": {
      "onhover": {
        "enable": true,
        "mode": "grab"
      },
      "onclick": {
        "enable": true,
        "mode": "push"
      },
      "resize": true
    },
    "modes": {
      "grab": {
        "distance": 140,
        "line_linked": {
          "opacity": 1
        }
      },
      "bubble": {
        "distance": 400,
        "size": 40,
        "duration": 2,
        "opacity": 8,
        "speed": 3
      },
      "repulse": {
        "distance": 200,
        "duration": 0.4
      },
      "push": {
        "particles_nb": 4
      },
      "remove": {
        "particles_nb": 2
      }
    }
  },
  
  ...
}

Connect all nodes

Is there something in the config that I can change to change that ? right now they are too spread apart and only a few connect. I would like them all to connect somehow, relative to how close they are maybe
Screen Shot 2021-02-16 at 2 11 26 PM

Error on assigning container

It does not work when trying to assign a container

var divContainer = $('#super-particles')
            new SuperParticles({
                container: divContainer
            })

Error:

SuperParticles.js:400 Uncaught RangeError: Maximum call stack size exceeded
    at SuperParticles._mergeDeep (SuperParticles.js:400)
    at SuperParticles._mergeDeep (SuperParticles.js:414)
    at SuperParticles._mergeDeep (SuperParticles.js:407)
    at SuperParticles._mergeDeep (SuperParticles.js:407)
    at SuperParticles._mergeDeep (SuperParticles.js:407)
    at SuperParticles._mergeDeep (SuperParticles.js:407)
    at SuperParticles._mergeDeep (SuperParticles.js:407)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.