# Import picographics library
import picographics

# Import numpy library
import numpy as np

# Create a PicoGraphics object with a 32x32 grid
pg = picographics.PicoGraphics(32, 32)

# Define a function to generate random RGB values
def random_rgb():
    return np.random.randint(0, 256, size=3)

# Define a function to draw a nebula of colors on the grid
def draw_nebula():
    # Clear the grid
    pg.clear()

    # Loop through each cell of the grid
    for x in range(32):
        for y in range(32):
            # Set the pen color to a random RGB value
            pg.set_pen(*random_rgb())

            # Draw a pixel at the current cell position
            pg.pixel(x, y)

    # Update the display with the drawn pixels
    pg.update()

# Define a function to loop the animation for 10 seconds
def loop_animation():
    # Import time library
    import time

    # Get the current time in seconds
    start_time = time.time()

    # Loop until 10 seconds have passed
    while time.time() - start_time < 10:
        # Draw a new nebula frame every 0.1 second
        draw_nebula()
        time.sleep(0.1)

# Run the animation loop function
loop_animation()