Monday, November 9, 2015

Field pathfinding

At the time this piece of code was written, I was investigating possible alternatives for pathfinding algorithms. This code came from an idea grown in my mind after working a bit with the fibrous system02 code I posted before. Fibrous system is based on proximity calculation: each agents checks distance to all other agents tail points. This is obviously computationally expensive especially when playing with big populations. The Fibrous system code was then optimized a bit introducing tree data structure, simply using Toxiclibs pointOcTree class, although you can notice improvements in the framerate only while playing with big populations. You can have a look at the code on openProcessing
At that time I was one of the backers of (the always great) Daniel Shiffman's "nature of code" project on Kickstarter and got fascinated by the chapters about Fields and Agents. The flowField class in the sketch linked below is a modification of the field class from Shiffman's book. I just added some functions for visualization and some agents behaviors. Each agent in the sketch reads data ( direction vectors) from the correspondent field's cell and overrides the previous cell with its current direction. The field becomes a substrate for agents communication (for a sort of pathfinding) and proximity calculation is completely avoided. You can try to run the sketch with 1 Million agents if you want, you will kill the framerate, but the sketch will run (consider that the rendering functions are completely unoptimized, just using VBO the code would run much faster). 

You can download the code here.
This the code I used to record this (crappy) video.

After running the sketch and let the system self organize a bit, you can press "c" to destabilize the field..the effects you will get are quite mesmerizing in my personal opinion and resemble a bit some natural behavior like slime mold diffusion .

I'm planning to upload these codes on Github too and I will start to do so from next week post on.
I have been thinking that maybe it would be generally more useful to make this publishing initiative more participatory, instead of being just me posting

If you have any question, critique or suggestion please drop a comment!

If you like the code and you would like to extend it in any way, we could work on it and post it again, so please drop a comment! 

If you have any idea on how to use this code for a project and want to collaborate, please drop a comment!

So well yes...drop a comment!:)

below some images of the sketch running:


  1. This comment has been removed by the author.

  2. Helllooo, amazing work. I want to use this for a project and require some help to convert this patterns to 2d drawings.Let me know. Thankssss!!