We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello creative coders ! I am learning processing, and am working a code with multiple particle systems.
I used kind of the same structure as dans shifman's nature of code example, system of systems, in which a new particle system appears when you click the mouse (see code here)
I want to do something kind of simple. Everytime i click the mouse, a particle system of a different color appears.
My color is defined in the Particle class with a function using noise :
void col(){
colorMode(HSB, 360, 100, 100);
c = map(noise(ct), 0, 1, 140, 360);
ct-= 0.05;
}
Should I work it here or in the ParticleSystem class? In words, how can I do this?
Answers
Allow the Particle class to store its own color in a variable. And this variable should be initialised inside the constructor. The constructor should therefore have an additional color argument.
BTW, the code you have given is quite stupid - line 3 does nothing at all.
Sorry, I corrected it. But ignore it. In shifman's example.. I would declare a new variable in the particlesystem class like :
particles.add(new Particle(origin, sysCol));
To display it :
But if I put
col = random(255);
to have a random greyscale value here, every particle would have a different color. I guess It needs to be in the ParticleSystem class.What I don't get is how modify/use a variable from a class to another. Sorry im just getting started
You should have the color for the particle store like this:-
Yes, @xxMrPHDxx you're probably right. But the OP's comments are a bit unclear, so the exact implementation may be different.
Yay thank you both ! Had no idea about
this.
Then research about it, it's important.
https://processing.org/reference/this.html
Using
this
is often unnecessary / redundant, but it can add clarity.But sometimes it's better/nescessary to use
this
because there's just no other way for a variable to pass itself into a function, if you understand me.