A simple firework animation with ipythonblocks.

In [1]:
from ipythonblocks import BlockGrid
In [2]:
import math
import itertools
In [3]:
def dist(p1, p2):
    return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
In [4]:
grid = BlockGrid(41, 41, block_size=8, lines_on=False)

red = (255, 43, 43)
orange = (255, 142, 43)
yellow = (248, 255, 43)
black = (0, 0, 0)
gray = (188, 188, 188)
blue = (15, 183, 255)
pink = (255, 79, 249)
green = (76, 224, 133)

# launch explosion
launch_center = (40, 20)

for i in (1, 2, 3, 2, 1):
    for block in grid:
        if dist((block.row, block.col), launch_center) < i*3:
            block.rgb = yellow
        else:
            block.rgb = black
        
        if dist((block.row, block.col), launch_center) < i*2:
            block.rgb = orange
        
        if dist((block.row, block.col), launch_center) < i:
            block.rgb = red

    grid.flash()

# ascent
for i in range(17):
    grid[:, :] = black
    row = 36 - i
    grid[row:row + 2, 20] = gray
    grid.flash()
    
# firework
firework_center = (20, 20)
colors = itertools.cycle((blue, pink, green))

for i in range(0, 20):
    grid[:, :] = black
    for j in range(0, i, 2):
        color = colors.next()
        for block in grid:
            if round(dist((block.row, block.col), firework_center)) == j:
                block.rgb = color
    grid.flash()

grid.show()