Particles.js: Change no. particles, properties on the fly?

Created on 4 Oct 2015  路  9Comments  路  Source: VincentGarreau/particles.js

Hihi,

Wondering how I can access the properties and change the no. of particles there are on the fly?

Thanks in advance!

Most helpful comment

Hi @kelvinz,

Yep you can:
pJSDom[0].pJS.particles.number.value = 30
pJSDom[0].pJS.fn.particlesRefresh()

All 9 comments

Hi @kelvinz,

Yep you can:
pJSDom[0].pJS.particles.number.value = 30
pJSDom[0].pJS.fn.particlesRefresh()

Thanks @VincentGarreau ! =)

When I change it, the background rerenders. So the existing nodes jump around. Is there a way to add nodes without the jumping?

Just started using this library, but yes it looks like the particlesRefresh() function resets everything.

If you want to do this at runtime you have to access the particle array directly, example:

$(document).on('click', function(e){
      const newColor = '#FF2222';
      $.each(pJSDom[0].pJS.particles.array, function(i,p){
        pJSDom[0].pJS.particles.array[i].color.value = newColor;
        pJSDom[0].pJS.particles.array[i].color.rgb = hexToRgb(newColor);
      });
 });

notice that to change color, you actually have to set the color.rgb value (ie not just the color.value), also the hexToRgb function is in the main particles.js file, this example refers to that function

i haven't tested everything yet but i'm pretty sure you could set any of the values of any particle at runtime using this method. hope that helps!

how can i do this from the angular particles library?

Just started using this library, but yes it looks like the particlesRefresh() function resets everything.

If you want to do this at runtime you have to access the particle array directly, example:

$(document).on('click', function(e){
      const newColor = '#FF2222';
      $.each(pJSDom[0].pJS.particles.array, function(i,p){
        pJSDom[0].pJS.particles.array[i].color.value = newColor;
        pJSDom[0].pJS.particles.array[i].color.rgb = hexToRgb(newColor);
      });
 });

notice that to change color, you actually have to set the color.rgb value (ie not just the color.value), also the hexToRgb function is in the main particles.js file, this example refers to that function

i haven't tested everything yet but i'm pretty sure you could set any of the values of any particle at runtime using this method. hope that helps!

Its working! But how we can change line color as well? i try with
pJSDom[0].pJS.particles.line_linked.color = newColor;
and nothing happend

UPDATE:

I found it, here is a link

Hi.

I'm trying to change some of the properties with either Jquery of JS.
I did it a while back and with the browser debugger, were able to see the library properties somewhere that showed the objects in a dropdown menu which made it very easy to find the object needed. No idea how to find it anymore. Any help would be appreciated.

I would like to do:
pJSDom[0].pJS.particles.array[i].shape.stroke.color

@sjhendriksz
Try to read core js, it helps me to find a solution

$(document).on('click', function(e){
const newColor = '#FF2222';
$.each(pJSDom[0].pJS.particles.array, function(i,p){
pJSDom[0].pJS.particles.array[i].color.value = newColor;
pJSDom[0].pJS.particles.array[i].color.rgb = hexToRgb(newColor);
});
});

I tried exactly this but it's changing the color of all the particles. Has anybody else tried changing the properties of a specific particle?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harshamv picture harshamv  路  3Comments

Adryd picture Adryd  路  7Comments

NoelAnnParisi picture NoelAnnParisi  路  4Comments

errogaht picture errogaht  路  7Comments

XRyu picture XRyu  路  6Comments