Connecting the dots
In this recipe we will show how to connect particles with lines and introduce another way of drawing particles.
Getting started
This recipe's code base is an example from the recipe Simulating particles flying on the wind (from Chapter 5, Building Particle Systems), so please refer to this recipe.
How to do it…
We will connect particles rendered as circles with lines.
Change the number of particles to create inside the
setup
method:int numParticle = 100;
We will calculate
radius
andmass
of each particle as follows:float radius = Rand::randFloat(2.f, 5.f); float mass = radius*2.f;
Replace the
draw
method inside theParticle.cpp
source file with the following:void Particle::draw(){ ci::gl::drawSolidCircle(position, radius); ci::gl::drawStrokedCircle(position, radius+2.f); }
Replace the
draw
method inside theParticleSystem.cpp
source file as follows:void ParticleSystem::draw(){ gl::enableAlphaBlending(); std::vector<Particle*>::iterator it; for(it = particles.begin...