Here is a follow-up on the flocking-experiments that I posted before.

Last time, all forces were created from the boids themselves by influencing each other. I started to add external forces now with which I hoped to get a little bit more direction into the simulation. These are the results of the first test.

The force I added is based on an input image. Before I start the simulation, I calculate the gradient on each pixel and store that in an internal data-structure. When the simulation is running, whenever a pixel is hit, I lookup this gradient, find a vector orthogonal to it and let the boid move in that direction. The resulting images and simulations can be seen here :)

So far this is highly experimental. I try different parameters, different input images and different colors. If you have suggestions, leave a comment :)

Great experiment! I have some questions:

Why and how do you calculate the ‘gradients of pixels’ beforehand?

I will try to do something similar in python over the weekend. I’ll let you know, if it works.

Thanks for the inspiration!

Hey Tonio!

As for the ‘why’ in your question: I use them indirectly to get the main edges in the image where I want the boids to travel along. The gradient will be biggest in those areas as it represents the change from one pixel to another which, of course, is big at edges. The gradient is orthogonal to the edge though and that’s why I create a vector that is orthogonal to the gradient which means that that one follows the direction of the edge. I hope that’s clear?

As for the ‘how’: The gradient is like the derivative in normal mathematical functions. Since an image is a discrete representation, we need to use something like central differences to get the derivative. A central difference is pretty much the same as those secant lines that are always shown when introducing derivatives in analysis classes. Does that help? Just look up central differences. It’s not complicated :)

Pixo, hey? ;)

Greetz, Matti.

Some of the stuff seems a little to difficult for me. But I will read it and see how far i get.

Yep, Pixo. Hannes showed me your site.

Cheers.

Just holla if you need an explanation of anything. It’s really not too difficult :) May seem daunting at first but the principles are pretty straight fwd.

edit: Just so that you don’t get confused -> You will need to calculate the derivatives in both directions of the image. Look up partial derivatives if you want a more mathematical explanation :)