def blit_aligned(
    surface_to_blit,
    target_surface,
    retrieve_pos_from="topleft",
    assign_pos_to="topleft",
    offset_pos_by=(0, 0),
):
    """Align and blit a surface into another.

    Works by aligning the position of the rects of two
    surfaces with an offset. The first surface is
    then blitted into the other one.

    Parameters
    ==========
    surface_to_blit (pygame.Surface instance)
        surface to be blitted into the other one.
    target_surface (pygame.Surface instance)
        surface wherein the first one will be blitted.
    retrieve_pos_from (string)
        name of pygame.Rect attribute from which to
        retrieve position information from the rect
        of the target surf.
    assign_pos_to (string)
        name of pygame.Rect attribute to which assign
        the position information in the rect of the
        surface to blit.
    offset_pos_by (tuple/list containing 02 integers)
        represent an offset applied to the rect of the
        surface to be blitted after the positions are
        aligned.
    """
    ### get pygame.Rect instances for both surfaces

    rect_for_blitting = surface_to_blit.get_rect()
    target_rect = target_surface.get_rect()

    ### align the positions between the two rects

    ## get the position from the target rect attribute
    target_pos = getattr(target_rect, retrieve_pos_from)

    ## assign the position to the rect of the surface
    ## to be blitted
    setattr(rect_for_blitting, assign_pos_to, target_pos)

    ### apply the offset to the rect of the surface to
    ### be blitted
    rect_for_blitting.move_ip(offset_pos_by)

    ### finally blit
    target_surface.blit(surface_to_blit, rect_for_blitting)
Align and blit a surface into another.

    Works by aligning the position of the rects of two
    surfaces with an offset. The first surface is
    then blitted into the other one.

    Parameters
    ==========
    surface_to_blit (pygame.Surface instance)
        surface to be blitted into the other one.
    target_surface (pygame.Surface instance)
        surface wherein the first one will be blitted.
    retrieve_pos_from (string)
        name of pygame.Rect attribute from which to
        retrieve position information from the rect
        of the target surf.
    assign_pos_to (string)
        name of pygame.Rect attribute to which assign
        the position information in the rect of the
        surface to blit.
    offset_pos_by (tuple/list containing 02 integers)
        represent an offset applied to the rect of the
        surface to be blitted after the positions are
        aligned.
    
nodezator/surfsman/draw.py