The scene was an existing one from 1:14 in Buck’s video, Onward Internet.
The first time round, I set out to reproduce it just to see if I could do it with my skillset. This was a good few months ago, and I didn’t save the original file so I used this morning to create it again from scratch.
I remembered my general approach to this scene but not the code itself. The scene is simply made from triangular masked solids with a rotation of (index-1)*18 so that when the layer is duplicated, the layer is rotated automatically, this is just a time saving trick so that I can easily create and delete the layers, like this:
Next there was a struggle to get the if/else statement right. A syntax that may make sense to me might not translate well to after effects, I had to tray a few different methods before I found one that worked. As a result though, I have learned a little more about how After Effects thinks with random numbers.
Eventually I managed to establish a code that worked, producing random colours from my palette of 6.
The only downfall of this is that the code did use pure random numbers meaning that some consecutive shapes had the same colour. I had to go into quite a few individual layers and change their colours, which defeats the point of using expressions to achieve that effect. To make this work as a script I’d have to code in some sort of clause that recognises the colours either side and ensures that those ones are different. The issue of course will also occur less if more colours are used.
Highlighted in purple are the layers that I had to change manually. Both on the base composition and on the 2nd layer composition.
Just for fun, here is a comparison to show my final shot next to the one from Buck.
Edit: November 14th 2016
It might be possible to develop a script from this, to create random colour backgrounds IF i can get my hands on the code behind the repeater function found in AE shape layers.