<commit_before>from __future__ import print_function
import sys
import time
import imread
import numpy as np


def timeit(fn):
    def new_fn(*args, **kwargs):
        start = time.time()
        ret = fn(*args, **kwargs)
        print("{} {:0.4f}s".format(fn.__name__, time.time() - start))
        return ret
    return new_fn


@timeit
def make_grid(img):
    rows = np.sum(img, axis=1)
    cols = np.sum(img, axis=0)
    print(img.shape)
    print(rows)
    print('--')
    print(rows.shape)
    print('--')
    print(cols.shape)


if __name__ == "__main__":
    img = imread.imread(sys.argv[1])
    make_grid(img)<commit_msg>Row mover with wraparound is working. Experimenting with moviepy.<commit_after>from __future__ import print_function

import sys
import random

import imread
import numpy as np
from moviepy.editor import VideoClip
from husl import rgb_to_husl


def make_grid(img):
    rows = np.sum(img, axis=1)
    cols = np.sum(img, axis=0)


def move(img_pixels, travel):
    """Shift `img_pixels` a distance of `travel` in the positive direction.
    The pixel array wraps around, so the last pixels will end up being
    the first pixels."""
    tail = img_pixels[-travel:].copy()  # pixel array wraps around
    img_pixels[travel:] = img_pixels[:-travel]  # move bulk of pixels
    img_pixels[:travel] = tail  # move the saved `tail` into vacated space


def _move_random(img):
    for row in img:
        move(row, random.choice(range(1, 5)))
    return img


def animate(img, make_frame, duration):
    animation = VideoClip(make_frame, duration=duration)
    animation.write_gif("bloop.gif", fps=24)


if __name__ == "__main__":
    img = imread.imread(sys.argv[1])
    make_grid(img)

    def rand_move(t):
        return _move_random(img)

    animate(img, rand_move, duration=3)
{'fraction_non_alphanumeric': 0.11862527716186252, 'fraction_numerical': 0.007206208425720621, 'mean_word_length': 3.4458128078817736, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3410144', 'n_tokens_mistral': 628, 'n_tokens_neox': 601, 'n_words': 173}