ofXParticleSystem

Hi,

Currently using this:

I want to make it so I can set the particle amount with each second or change of a variable. For example, being able to set the particleamount to 10 when a variable is above 5, and then setting the particleamount to 20 when the variable is above ten.

Could anyone help me do this? Quite confused as to the best way of doing it.

I would not use that addon. It is 6 years old and it is targeting OF version 007.
Just start from scratch:
http://natureofcode.com/book/chapter-4-particle-systems/

1 Like

Damn, that one had everything I needed other than the set particles code :joy: Do you know of any other addons which may do particles? I’ll make sure to take a look at what you linked, too!

You can keep using it. I do not know if it works.
If you want to change the number of particles, Instead of resizing the vector container, that it is defined in the setup method, and that internally it is using an std::vector

particleSystem = ofxParticleSystem(100);

I would change the draw method, instead of

    ofBackground(0, 0, 0);
    
    ofSetColor(255, 0, 0);
   
    particleSystem.draw();

You could implement some custom logic where you draw only certain particle, for example, to draw just the first 20.

for (int i =0; i < 20; i++) {
    particleSistem.particles[i].draw();
}

Hi,

Struggling a little bit with this unfortunately. I’ve changed

std::list<ofxParticle> particles;

to

std::vector<ofxParticle> particles;

But this brings about a whole host of errors. I don’t think I’m knowledgeable enough to fix these, so any help on how to proceed would be much appreciated and once again many thanks for your help so far.

I did add so far:

if (ofGetElapsedTimef() < 20) {
verdana14.drawString("Think about your most challenging assignment you need to hand in....", 400, 150);
for (int i = 0; i < 20; i++) {
particleSystem.particles[i].draw();
} 
}

Sorry, I did not noticed that the addon you are linking it is using a list, not a vector. Try to use a list instead of a vector. When you have an error, post some code so that we can help you.

Sorry to be a pain but how would I do that loop as a list?

int i = 0;
for (auto const& p : particleSystem.particles) {
    if(i < 20){
        p.draw();
        i++
    }
}

I did not test it

Hi,

Now I get this error: https://i.imgur.com/C1ySpOm.png

try

int i = 0;
for (auto const& p : particleSystem.particles) {
    if(i < 20){
        p->draw();
        i++
    }
}

And have a look at list in c++ http://en.cppreference.com/w/cpp/container/list. It can be useful when debugging

Hi,

Thank you I’ll take a look at that!

I get this problem now: