@ A.M
I know, I start reading about particle system because 3ds max, although I did not delve into it because GG did not use the particle system yet.
Anyway I hope that the average user does not need a master's degree in physics, mathematics, trigonometry, geometry, etc. to be able to use the particle system in GG.
Anyway your tuto is useful to understand the new LUA command to deal with.
@ everybody interested about who like deal with, searching for info, or simply curiosity.
Summarizing the concept a lot, a particle is an object, and a particle system is a collection of those objects, often represented by a simple shape or dot. GG use a sprite sheet.
This piece of code is not mine, but I think it recreates quite well the way to create a particle. It has location, velocity, and acceleration, a constructor to initialize those variables, and functions to display() itself, and update() its location.
Particle p;
void setup() {
size(640,360);
p = new Particle(new PVector(width/2,10));
}
void draw() {
background(255);
// Operating the single Particle
p.run();
if (p.isDead()) {
println("Particle dead!");
}
}
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
float lifespan;
Particle(PVector l) {
//[offset-up] For demonstration purposes we assign the Particle an initial velocity and constant acceleration.
acceleration = new PVector(0,0.05);
velocity = new PVector(random(-1,1),random(-2,0));
location = l.get();
lifespan = 255.0;
}
// Sometimes it’s convenient to have a “run”
// function that calls all the other functions we need.
void run() {
update();
display();
}
void update() {
velocity.add(acceleration);
location.add(velocity);
lifespan -= 2.0;
}
void display() {
stroke(0,lifespan);
fill(0,lifespan);
ellipse(location.x,location.y,8,8);
}
// Is the Particle alive or dead?
boolean isDead() {
if (lifespan < 0.0) {
return true;
} else {
return false;
}
}
}
Here the author is using an ellipse, drawning it directly on the screen via code, instead of using a shape, referencing a "PImage" to draw the particle.
Usually particle systems involve something called an "emitter", the emitter is the source of the particles and controls the initial settings for the particles, location, velocity, etc. and for perfomance sake, as new particles are born, we need old particles to die; otherwise our system would go crazy, and we run on the risck to thrown it thru the windows, LOL.
Here comes into the scenary "lifespan" to help with. Usually going from 255 thru 0 (and the timer will start at 255 and count down to 0); it does thus because to act as the alpha transparency as well. When the particle is "dead" it will also have faded away onscreen.
On code "boolean isDead()" check out and see if the value of "lifespan" is less than 0. If it is return true, otherwise return false.
"run()" function calls both "update()" and "display()" . In addition, it give the particle a random initial velocity as well as a downward acceleration (to simulate gravity).
Of course there are another parameters involved, such as force, repellers, gravity etc implied in the behavior of the particles.
Hope this help to clarify something, many of the function used as already declare in another class of course, but not necessary to explain this concept.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz
OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4