Ant game

This is currently done as a zero player game... I wrote many different versions of this. maybe will clean up and add some of the others some time. I learned about the ant game from Ivars Peterson's book, The Mathematical Tourist.
In the ant game, the ants move on a trouchet path, and after moving through (or while moving through or whatever rule you decide) they change the direction of the path).
It's nice to do this on a really big board and leave a trail, but takes up more GPU. In this version, I have 4 ants. Fun fact: no matter how many ants, if they all start on different squares, they never colide. But they can enter the same square on different paths. When this happens, I decided not to change the path directions. Could use a different rule.
I like to look for cycles, i.e., from a particular initial position, how long does it take to get back to that position, if at all? Eventually everything ends in a cycle, since this is running on a torus.
I restricted to 4 ants just to reduce the number of uniforms needed in the glsl, could increase a bit, but am limited. The dots apear when you move the mouse over the screen. Probably none of this works on a touch screen.


The cyan and red dots on the screen can be moved around to control the ant speed, ant size, path width, and path colours. Each path has a colour depending on its length. As paths break and rejoin the colours change, since the lengths change.

download image Or mouse: colours=
There is a problem with the boundary, that needs a bit of work for colours to work out... see im=0 etc // v_p6.w is the total length of the paths