BTW, I was able to get a version of this looking decent using Link, the logic looks much simpler too! A good use of the new cross product method:
var ra = [ 0, 96, 192, 255 ];
var ga = [ 0, 96, 192, 255 ];
var ba = [ 0, 96, 192, 255 ];
var row = 0;
Link(ba).cross(ga).cross(ra).each(function(item, i) {
if (i % 4 === 0) row++;
Rectangle(i * 8, row * 8, 8, 8, CreateColor(item.C, item.B, item.A));
});
The reason it looks different is because Link has a tendency to flatten arrays. We lose some information. BTW, currently this is due to the fact i is looping between the range [0, 3]. I'm still working on the indexer for the cross product. Because I could also make i the range of the values.
Mooch: BTW the "permutator" you are looking for is called the "set cross product". The idea is you take all the things of an array, A and pair them with all of the things of an array, B, thus creating all of the combinations. Defined as: { A × B = (x ,y) | x ∈ A, y ∈ B }
[1, 2] cross [3, 4] is: {(1, 3), (1, 4), (2, 3), (2, 4)}.
Edit: For posterity the new link version for this would look like:
var ra = [ 0, 96, 192, 255 ];
var ga = [ 0, 96, 192, 255 ];
var ba = [ 0, 96, 192, 255 ];
var row = -1, col = 0;
Link(ba).cross(ga).cross(ra).each(function(item, i) {
if (i % 4 === 0) row++;
if (row === 8) { row = 0; col = 32; }
Rectangle(col + i * 8, row * 8, 8, 8, CreateColor(item[2], item[1], item[0]));
});