FlockDraw

FlockDraw

A Quick Intro…

After a long while without coding anything that produces interesting visual effects, I took the initiative to do something. I went through some difficulties because I had to choose a lib to use and lots of options were available. I could remember some OpenGL and get my hands really dirty, but I would take too long to finish it. So I decided to take a look on some “artistic” frameworks or libraries.

Considering that I am absolutely ignorant regarding Java, processing was not an option, however I found two interesting projects: openFrameworks and libCinder. I must admit that I just randomly chose one and it was libCinder.

This project is the result of the study of libCinder usage and API and took advantage of this time to explore a little bit of C++11. It is a mix of one of the tutorials presented (“Hello Cinder!” authored by Robert Hodgin – this guy is a genius), some techniques that I got in my old image processing times and some crazy ideas. I got pretty satisfied with the results, that you can see on the following video (if you are lazy enough to avoid downloading the executable and testing by yourself).

 

The principle is simple: each particle haves the average color from the area that they are occupying and the size is dictated by the luminosity of this color. The movement and trails are produced by a few simple things:

Flocking Algorithm

The flocking algorithm is the behavior of individuals that tends to be grouped while moving, just like fish schooling. It controls the basic movement of the particles, keeping them grouped, aligned and not overlapped. And the method to do that in lines of code is pretty simple. An outline can be found on Wikipedia, and more detailed descriptions can be found on the tutorial mentioned above, and on references like this one (by the father of the flocking technique).

I was always curious to know how these algorithms worked. It was a good opportunity to learn. After all, I did few modifications on the flocking algorithm proposed by the tutorial.

Color guidance

Each particle moves to the adjacent areas which have the closest color to the actual color. The color guidance makes the particles deviate from the other particles, creating a turbulence in the movement and adding a little bit more of chaos to the constructed image.

Accumulation buffer

The accumulation buffer is a very old technique to emulate motion blur. I use accumulation buffers because it’s easy to code, haves terrific results and good performance. It would be heavy to maintain thousands of trails for the particles being displayed.

Download and sources

If you want to take a look at the program, you can download it here or compile by yourself. The sources are available under Apache License at GitHub!

This project is dependent of the SimpleGUI Cinder Block (the version that I’m maintaining).