Source

sketchbook / demo / rotate.py

Full commit
from matrix import Transform, rotation_matrix

class Rotate(object):
    def __init__(self, grid, iterations, tile_size=1):
        self.grid = grid 
        self.w = len(grid[0])
        self.h = len(grid)
        self.ts = tile_size

        self.iteration = iterations
        self.iter_total = iterations

        m = rotation_matrix(2.0, self.w/2.0, self.h/2.0, 2.5)
        self.T = Transform(grid)

    def get_grid(self):
        offset = self.iter_total - self.iteration
        m = rotation_matrix(offset*2.0, self.w/2.0, self.h/2.0, 2.5)
        new_grid = self.T.apply_matrix_clip(m, offset)

        self.iteration -= 1
        return new_grid