<jupyter_start><jupyter_text>Creating and indexing block grids<jupyter_code>from ipythonblocks import BlockGrid
b = BlockGrid(5, 5, fill=(255, 0, 0))
b[2,2].blue = 255
b[2,2].green = 255
b
b = BlockGrid(11, 7, fill=(255, 120, 0))
b[:, 1::2] = (128, 0, 128)
b[2:5,3:-3] = (120,120,120)
b<jupyter_output><empty_output><jupyter_text>Animation<jupyter_code>grid = BlockGrid(3, 3)

previous_block = None

for block in grid.animate():
    block.green = 255
    
    if previous_block:
        previous_block.green = 0
    
    previous_block = block
def bounds(i, lower, upper):
    i = min((i, upper))
    i = max((i, lower))
    return i
from random import randint

grid = BlockGrid(20, 10)

x = 10
y = 5
color = [128, 128, 128]

while True:
    x = bounds(x+randint(-1, 1), 0, 19)
    y = bounds(y+randint(-1, 1), 0, 9)
    idx = randint(0,2)
    color[idx] = bounds(color[idx] + randint(-20, 20), 0, 255)   
    grid[y,x] = color
    grid.flash(display_time=0.05)<jupyter_output><empty_output><jupyter_text>Saving grid as image<jupyter_code>import PIL

grid.save_image('blocks.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15765765765765766, 'fraction_numerical': 0.08378378378378379, 'mean_word_length': 4.167441860465116, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '260391', 'license': 'MIT', 'n_tokens_mistral': 521, 'n_tokens_neox': 450, 'n_words': 104, 'path': 'ipythonblocks/IPythonblocks.ipynb', 'repo_name': 'yunzhang599/Python3_Package_Examples', 'size': '1110'}