Rotate a matrix clockwise or counterclockwise