I had the idea for this experiment a few months ago and I’ve actually attempted it a few times - each iteration being close to what I was intending to achieve but alas, not close enough. This time I’m happy enough with the solution to release it to the world.

I’ve decided that I’m really quite fascinated with three concepts in particular, broadly these are - 1) Automata/Intelligent Agents 2) Intransitivity (the Rock-Paper-Scissors rule set), and 3) Organising information spatially, or by proximity. You’ll see these ideas again and again throughout this site (and no doubt even more in the future!).
This latest adventure touches on all three of these concepts. Brace yourself.
So I was thinking about things that occur in 3’s… the two I settled with were Triangles (3 sides) and Colour (which can be composed of three entities, Red, Green and Blue). I briefly thought about the three dimensions of space (X, Y and Z axes), but decided to leave that until another time.
Below you’ll see a grid of triangles that are initialised to a random colour. In each iteration of the program, two phases occur: Combat and Render.
To get your head around the Combat phase, you’ll first need to know the overarching rule that Red conquers Green, Green conquers Blue and Blue conquers Red.
… Red > Green > Blue > Red …
The pseudocode for the process looks like this:
- Figure out if I’m predominantly Red, Green or Blue by looking at my hex components.
- Find the average colour of my three adjacent Triangles and find their predominant colour.
- If we both have the same predominant colour, set my colour to the average between me and them.
- If I win the fight, set my most dominant colour component to max (255) and my least dominant colour component to zero.
- If I lose the fight, set my least dominant colour component to max and my most dominant to zero
In the Render phase… um… the Triangles get re-rendered.
So that’s pretty much it… you’ll notice a number of colourful blotches partitioned by static - this is where the fighting is currently at its most fierce!
Note - if you click the applet, each Triangle will reset to a random colour.
Hope it kinda makes sense. Let me know if you can think of other algorithms to make use of the triangle/colour partnership.
If you liked this post, you’ll probably also like:
PS - The project I’ve been sweating over launched last Friday. I’ll post about it soon.







