def unite_surfaces(
    surfaces: Iterable,
    rects: Iterable,
) -> [
    {'name': 'union_surf', 'type': Surface},
]:
    """Return union of surfaces positioned with given rects.

    The generated image has per pixel alphas (it is generated with
    Surface.convert_alpha and made fully transparent before drawing
    the given surfaces on it) so you might want to convert it back
    afterwards with Surface.convert().
    """
    ### create union rect and surface

    first, *remaining = rects

    union_rect = first.unionall(remaining)

    union_surf = Surface(union_rect.size).convert_alpha()
    union_surf.fill((0, 0, 0, 0)) # make fully transparent

    ### position and blit surfaces on union

    offset = tuple(-coordinate for coordinate in union_rect.topleft)

    for surf, rect in zip(surfaces, rects):
        union_surf.blit(surf, rect.move(offset))

    ### finally return it
    return union_surf
Return union of surfaces positioned with given rects.

    The generated image has per pixel alphas (it is generated with
    Surface.convert_alpha and made fully transparent before drawing
    the given surfaces on it) so you might want to convert it back
    afterwards with Surface.convert().
    
nodezator/graphman/capsulenode/pygamedefs.py