rotate() tries to get fourth col of a matrix having only two cols:
trace.sm (100 КиБ) скачан 38 раз(а).Actually, I didn't try to understand the algo yet, so I have no clue how to improve it.
Edit:
in the original algo, there's no line like
s:augment(col(s,2),col(s,4))
Removing it gives another error: j becomes -14, and this index isn't OK as a matrix col.

Edit 2: here it is, should work for 5346:
Rotate Image.sm (407 КиБ) скачан 43 раз(а). (updated for 2x speed using eval()).
Edit: and here is the colored version (great thanks to Alex Melnik):
Rotate Image+color.sm (414 КиБ) скачан 36 раз(а).
С уважением,
Михаил Каганский