Adding a tail to our particles
In this recipe, we will show you how to add a tail to the particle animation.
Getting started
In this recipe we are going to use the code base from the recipe Applying repulsion and attraction forces from Chapter 5, Building Particle Systems.
How to do it…
We will add a tail to the particles using different techniques.
Drawing history
Simply replace the draw
method with the following code:
void MainApp::draw() { gl::enableAlphaBlending(); gl::setViewport(getWindowBounds()); gl::setMatricesWindow(getWindowWidth(), getWindowHeight()); gl::color( ColorA(0.f,0.f,0.f, 0.05f) ); gl::drawSolidRect(getWindowBounds()); gl::color( ColorA(1.f,1.f,1.f, 1.f) ); mParticleSystem.draw(); }
Tail as a line
We will add a tail constructed from several lines.
Add new properties to the
Particle
class inside theParticle.h
header file:std::vector<ci::Vec2f> positionHistory; int tailLength;
At the end of the
Particle
constructor, inside theParticle.cpp
source file, set the default...