docs/notebooks/sprator_streamlit/CellularSprites.py
def make_sprite(
    n_sprites: int,
    n_iters: int,
    repro_rate: int,
    stasis_rate: int,
):
    """Main function for creating sprites

    Parameters
    ----------
    n_sprites : int
        Number of sprites to generate
    n_iters : int
        Number of iterations to run the simulator
    repro_rate : int
        Inverse reproduction rate
    stasis_rate : int
        Stasis rate
    """
    logger.info("Initializing board")
    board = sg.Board(size=(8, 4))

    logger.info("Running simulation")
    sprator_list = []

    for sprite in range(n_sprites):
        noise = np.random.choice([0, 1], size=(8, 4))
        custom_lf = lf.Custom(noise)
        board.add(custom_lf, loc=(0, 0))
        sim = sg.Simulator(board)
        sim.run(
            custom_rule,
            iters=n_iters,
            repro_rate=repro_rate,
            stasis_rate=stasis_rate,
        )
        fstate = sim.get_history()[-1]

        logger.info(f"Generating sprite/s: {sprite}")
        sprator = np.hstack([fstate, np.fliplr(fstate)])
        sprator = np.pad(
            sprator, mode="constant", pad_width=1, constant_values=1
        )
        sprator_with_outline = add_outline(sprator)
        sprator_gradient = get_gradient(sprator_with_outline)
        sprator_final = combine(sprator_with_outline, sprator_gradient)
        sprator_list.append(sprator_final)

    # Generate plot based on the grid size
    n_grid = int(sqrt(n_sprites))

    # Generate random colors as cmap
    r = lambda: "#%02X%02X%02X" % (
        random.randint(0, 255),
        random.randint(0, 255),
        random.randint(0, 255),
    )
    colors = ["black", "#f2f2f2", r(), r(), r()]
    cm.register_cmap(
        cmap=mpl.colors.LinearSegmentedColormap.from_list(
            "custom", colors
        ).reversed()
    )

    if n_grid == 1:
        fig, axs = plt.subplots(n_grid, n_grid, figsize=(5, 5))
        axs = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
        axs.imshow(sprator_list[0], cmap="custom_r", interpolation="nearest")
        fig.text(0, -0.05, "bit.ly/CellularSprites", ha="left", color="black")
    else:
        fig, axs = plt.subplots(n_grid, n_grid, figsize=(5, 5))
        for ax, sprator in zip(axs.flat, sprator_list):
            # TODO: Remove duplicates
            # Generate random colors as cmap
            r = lambda: "#%02X%02X%02X" % (
                random.randint(0, 255),
                random.randint(0, 255),
                random.randint(0, 255),
            )
            colors = ["black", "#f2f2f2", r(), r(), r()]
            cm.register_cmap(
                cmap=mpl.colors.LinearSegmentedColormap.from_list(
                    "custom", colors
                ).reversed()
            )
            ax.imshow(sprator, cmap="custom_r", interpolation="nearest")
            ax.set_axis_off()
        fig.text(0.125, 0.05, "bit.ly/CellularSprites", ha="left")

    return fig
Main function for creating sprites

    Parameters
    ----------
    n_sprites : int
        Number of sprites to generate
    n_iters : int
        Number of iterations to run the simulator
    repro_rate : int
        Inverse reproduction rate
    stasis_rate : int
        Stasis rate
    
Main function for creating sprites
Parameters

n_sprites : int
Number of sprites to generate
n_iters : int
Number of iterations to run the simulator
repro_rate : int
Inverse reproduction rate
stasis_rate : int
Stasis rate
Main function for creating sprites Parameters n_sprites : int Number of sprites to generate n_iters : int Number of iterations to run the simulator repro_rate : int Inverse reproduction rate stasis_rate : int Stasis rate
def make_sprite(
    n_sprites: int,
    n_iters: int,
    repro_rate: int,
    stasis_rate: int,
):
    logger.info("Initializing board")
    board = sg.Board(size=(8, 4))
    logger.info("Running simulation")
    sprator_list = []
    for sprite in range(n_sprites):
        noise = np.random.choice([0, 1], size=(8, 4))
        custom_lf = lf.Custom(noise)
        board.add(custom_lf, loc=(0, 0))
        sim = sg.Simulator(board)
        sim.run(
            custom_rule,
            iters=n_iters,
            repro_rate=repro_rate,
            stasis_rate=stasis_rate,
        )
        fstate = sim.get_history()[-1]
        logger.info(f"Generating sprite/s: {sprite}")
        sprator = np.hstack([fstate, np.fliplr(fstate)])
        sprator = np.pad(
            sprator, mode="constant", pad_width=1, constant_values=1
        )
        sprator_with_outline = add_outline(sprator)
        sprator_gradient = get_gradient(sprator_with_outline)
        sprator_final = combine(sprator_with_outline, sprator_gradient)
        sprator_list.append(sprator_final)
    n_grid = int(sqrt(n_sprites))
    r = lambda: "#%02X%02X%02X" % (
        random.randint(0, 255),
        random.randint(0, 255),
        random.randint(0, 255),
    )
    colors = ["black", "#f2f2f2", r(), r(), r()]
    cm.register_cmap(
        cmap=mpl.colors.LinearSegmentedColormap.from_list(
            "custom", colors
        ).reversed()
    )
    if n_grid == 1:
        fig, axs = plt.subplots(n_grid, n_grid, figsize=(5, 5))
        axs = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
        axs.imshow(sprator_list[0], cmap="custom_r", interpolation="nearest")
        fig.text(0, -0.05, "bit.ly/CellularSprites", ha="left", color="black")
    else:
        fig, axs = plt.subplots(n_grid, n_grid, figsize=(5, 5))
        for ax, sprator in zip(axs.flat, sprator_list):
            r = lambda: "#%02X%02X%02X" % (
                random.randint(0, 255),
                random.randint(0, 255),
                random.randint(0, 255),
            )
            colors = ["black", "#f2f2f2", r(), r(), r()]
            cm.register_cmap(
                cmap=mpl.colors.LinearSegmentedColormap.from_list(
                    "custom", colors
                ).reversed()
            )
            ax.imshow(sprator, cmap="custom_r", interpolation="nearest")
            ax.set_axis_off()
        fig.text(0.125, 0.05, "bit.ly/CellularSprites", ha="left")
    return fig
def make_sprite ( n_sprites : int , n_iters : int , repro_rate : int , stasis_rate : int , ) : logger . info ( "Initializing board" ) board = sg . Board ( size = ( 8 , 4 ) ) logger . info ( "Running simulation" ) sprator_list = [ ] for sprite in range ( n_sprites ) : noise = np . random . choice ( [ 0 , 1 ] , size = ( 8 , 4 ) ) custom_lf = lf . Custom ( noise ) board . add ( custom_lf , loc = ( 0 , 0 ) ) sim = sg . Simulator ( board ) sim . run ( custom_rule , iters = n_iters , repro_rate = repro_rate , stasis_rate = stasis_rate , ) fstate = sim . get_history ( ) [ - 1 ] logger . info ( f"Generating sprite/s: {sprite}" ) sprator = np . hstack ( [ fstate , np . fliplr ( fstate ) ] ) sprator = np . pad ( sprator , mode = "constant" , pad_width = 1 , constant_values = 1 ) sprator_with_outline = add_outline ( sprator ) sprator_gradient = get_gradient ( sprator_with_outline ) sprator_final = combine ( sprator_with_outline , sprator_gradient ) sprator_list . append ( sprator_final ) n_grid = int ( sqrt ( n_sprites ) ) r = lambda : "#%02X%02X%02X" % ( random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) , ) colors = [ "black" , "#f2f2f2" , r ( ) , r ( ) , r ( ) ] cm . register_cmap ( cmap = mpl . colors . LinearSegmentedColormap . from_list ( "custom" , colors ) . reversed ( ) ) if n_grid == 1 : fig , axs = plt . subplots ( n_grid , n_grid , figsize = ( 5 , 5 ) ) axs = fig . add_axes ( [ 0 , 0 , 1 , 1 ] , xticks = [ ] , yticks = [ ] , frameon = False ) axs . imshow ( sprator_list [ 0 ] , cmap = "custom_r" , interpolation = "nearest" ) fig . text ( 0 , - 0.05 , "bit.ly/CellularSprites" , ha = "left" , color = "black" ) else : fig , axs = plt . subplots ( n_grid , n_grid , figsize = ( 5 , 5 ) ) for ax , sprator in zip ( axs . flat , sprator_list ) : r = lambda : "#%02X%02X%02X" % ( random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) , random . randint ( 0 , 255 ) , ) colors = [ "black" , "#f2f2f2" , r ( ) , r ( ) , r ( ) ] cm . register_cmap ( cmap = mpl . colors . LinearSegmentedColormap . from_list ( "custom" , colors ) . reversed ( ) ) ax . imshow ( sprator , cmap = "custom_r" , interpolation = "nearest" ) ax . set_axis_off ( ) fig . text ( 0.125 , 0.05 , "bit.ly/CellularSprites" , ha = "left" ) return fig
Main function for creating sprites
Parameters
Main function for creating sprites Parameters
"""Main function for creating sprites

    Parameters
    ----------
    n_sprites : int
        Number of sprites to generate
    n_iters : int
        Number of iterations to run the simulator
    repro_rate : int
        Inverse reproduction rate
    stasis_rate : int
        Stasis rate
    """ # Generate plot based on the grid size # Generate random colors as cmap # TODO: Remove duplicates # Generate random colors as cmap
n_sprites
int
n_iters
int
repro_rate
int
stasis_rate
int