Aligning particles to a processed image
In this recipe, we will show how you can use techniques you were introduced to in the previous recipes to make particles align to the edge detected in the image.
Getting ready
In this recipe, we are going to use the particles' implementation from the Creating a particle system in 2D recipe; the image processing example from the Detecting edges recipe in Chapter 3, Using Image Processing Techniques; as well as simulating repulsion covered in the Applying repulsion and attraction forces recipe.
How to do it…
We will create particles aligning to the detected edges in the image. Perform the following steps to do so:
Add an
anchor
property to theParticle
class in theParticle.h
file.ci::Vec2f anchor;
Set the
anchor
value at the end of theParticle
class constructor in theParticle.cpp
source file.anchor = position;
Add a new property to your application's main class.
float maxAlignSpeed;
At the end of the
setup
method, after image processing, add new particles...