Pattern rule generation NeoMatrix

But how is your matrix wired?
Is it a raster or a serpentine raster. That determines what you need to do to write those routines.

Draw it out, have the first LED, that is LED zero at the bottom left corner. Then write down the numbers of the LEDs as they would appear on the matrix, only do the first n x 3,where n is the size of the biggest side of the matrix.

Then I can show you how to work it out.