def scale_hrz(s):
    scaled = []
    for i, row in enumerate(s):
        r = ""
        for j in range(len(row) - 1):        
            if row[j] == '+' and row[j + 1] == '+':
                r += '+-'
            elif row[j] == '+' and row[j + 1] == ' ':
                r += '+ '
            elif row[j] == '+' and row[j + 1] == '-':
                r += '+-'
            elif row[j] == '-' and row[j + 1] == '-':
                r += '--'
            elif row[j] == ' ':
                r += '  '
            elif row[j] == '|' and row[j + 1] == '|':
                r += "| "
            elif row[j] == '|' and row[j + 1] == ' ':
                r += "| "
            elif row[j] == '|' and row[j + 1] == '+':
                r += "| "
            elif row[j] == '+' and row[j + 1] == '|':
                r += "+ "            
            elif row[j] == '-' and row[j + 1] == '+':
                r += '--'
            else:
                print("no h", row[j], row[j + 1])
        r += row[-1]
        scaled.append(r)
    return scaled


def scale_vert(s):
    n, m = len(s), len(s[0])
    scaled = [[' '] * m for i in range(2 * n - 1)]
    for j in range(m):
        for i in range(n - 1):        
            if s[i][j] == '+' and s[i + 1][j] == '+':
                scaled[2 * i][j] = '+'
                scaled[2 * i + 1][j] = '|'
            elif s[i][j] == '+' and s[i + 1][j] == '|':
                scaled[2 * i][j] = '+'
                scaled[2 * i + 1][j] = '|'
            elif s[i][j] == '|' and s[i + 1][j] == '|':
                scaled[2 * i][j] = '|'
                scaled[2 * i + 1][j] = '|'
            elif s[i][j] == ' ':
                scaled[2 * i][j] = ' '
                scaled[2 * i + 1][j] = ' '
            elif s[i][j] == '-' and s[i + 1][j] == '-':
                scaled[2 * i][j] = '-'
                scaled[2 * i + 1][j] = ' '
            elif s[i][j] == '-' and s[i + 1][j] == ' ':
                scaled[2 * i][j] = '-'
                scaled[2 * i + 1][j] = ' '
            elif s[i][j] == '|' and s[i + 1][j] == '+':
                scaled[2 * i][j] = '|'
                scaled[2 * i + 1][j] = '|'
            elif s[i][j] == '-' and s[i + 1][j] == '+':
                scaled[2 * i][j] = '-'
                scaled[2 * i + 1][j] = ' '
            elif s[i][j] == '+' and s[i + 1][j] == ' ':
                scaled[2 * i][j] = '+'
                scaled[2 * i + 1][j] = ' '
            elif s[i][j] == '+' and s[i + 1][j] == '-':
                scaled[2 * i][j] = '+'
                scaled[2 * i + 1][j] = ' '
            else:
                print("no v", s[i][j], s[i + 1][j])
        scaled[-1][j] = s[-1][j]
        
    return [''.join(row) for row in scaled]

def down_scale_hrz(s):
    scaled = []
    for i, row in enumerate(s):
        r = ""
        for j in range(len(row) // 2): 
            if row[2 * j] == '+' and row[2 * j + 1] == '-':
                r += '+'
            elif row[2 * j] == '+' and row[2 * j + 1] == ' ':
                r += '+'
            elif row[2 * j] == '+' and row[2 * j + 1] == '-':
                r += '+'
            elif row[2 * j] == '-' and row[2 * j + 1] == '-':
                r += '-'            
            elif row[2 * j] == ' ' and row[2 * j + 1] == ' ':
                r += ' '
            elif row[2 * j] == '|' and row[2 * j + 1] == ' ':
                r += '|'
            elif row[2 * j] == ' ' and row[2 * j + 1] == ' ':
                r += ' '
            elif row[2 * j] == '+' and row[2 * j + 1] == ' ':
                r += '+'
            elif row[2 * j] == '-' and row[2 * j + 1] == ' ':
                r += ' '
            else:
                print("no h", row[j], row[j + 1])
        r += row[-1]
        scaled.append(r)
    return scaled

def down_scale_vert(s):
    n, m = len(s), len(s[0])
    scaled = [[' '] * m for i in range(n // 2 + 1)]
    for j in range(m):
        for i in range(n // 2):        
            if s[2 * i][j] == '+' and s[2 * i + 1][j] == '|':
                scaled[i][j] = '+'
            elif s[2 * i][j] == '+' and s[2 * i + 1][j] == '|':
                scaled[i][j] = '+'
            elif s[2 * i][j] == '|' and s[2 * i + 1][j] == '|':
                scaled[i][j] = '|'
            elif s[2 * i][j] == ' ' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = ' '
            elif s[2 * i][j] == '-' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = '-'
            elif s[2 * i][j] == '-' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = '-'
            elif s[2 * i][j] == '|' and s[2 * i + 1][j] == '|':
                scaled[2 * i][j] = '|'
            elif s[2 * i][j] == '-' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = '-'
            elif s[2 * i][j] == '+' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = '+'
            elif s[2 * i][j] == '+' and s[2 * i + 1][j] == ' ':
                scaled[i][j] = '+'
            else:
                print("no v", "fst :", s[2 * i][j], "snd:", s[2 * i + 1][j])
        scaled[-1][j] = s[-1][j]
        
    return [''.join(row) for row in scaled]
    
def scale(_shape):
    m = max(len(row) for row in _shape)
    shape = [row.ljust(m, ' ') for row in _shape]
    hs = scale_hrz(shape)
    vs = scale_vert(hs)
    return vs

def downscale(shape):
    vs = down_scale_vert(shape)
    hs = down_scale_hrz(vs)
    return '\n'.join(hs)
shape = '''         +-+
         | |
         | |
   +-----+ |
   |+-+    |
   || |  +-+
+--+| +--+
|   |
+---+'''.split('\n')
def tester(shape):
    scaled = scale(shape)
    print('\n'.join(scaled))
    down = downscale(scaled)
    print(down)
tester(shape)


def break_pieces(shape):
    arr = [list(row) for row in shape.split("\n")]
    n = len(arr)
    m = max(len(arr[i]) for i in range(n))
    for i in range(n):
        arr[i].extend([' ' for _ in range(m - len(arr[i]))])
    spaces = set([(i, j) for i in range(n) for j in range(m) if arr[i][j] == " "])
    
    
    def get_component(u, v):
        frontier = set()
        seen = set([(u, v)])
        q = [(u, v)]
        while len(q) > 0:
            x, y = q.pop(0)            
            for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                s, t = x + dx, y + dy
                if 0 <= s < n and 0 <= t < m and not (s, t) in seen:
                    if arr[s][t] != " ":
                        frontier.add((s, t))                        
                    else:
                        seen.add((s, t))
                        q.append((s, t))
            for dx, dy in ((1, 1), (1, -1), (-1, 1), (-1, -1)):
                s, t = x + dx, y + dy
                if 0 <= s < n and 0 <= t < m and not (s, t) in seen:
                    if arr[s][t] != " ":
                        frontier.add((s, t))
        return (seen, [[arr[x][y] if (x, y) in frontier else " " for y in range(m)] for x in range(n)])
    
    
    def clean_frontier(fr):
        new_fr = [x for x in fr if any(c != " " for c in x)]
        def cnt_spaces(s):
            i = 0
            while i < len(s) and s[i] == " ": i += 1
            return i    
        m = min(cnt_spaces(x) for x in new_fr)
        for i in range(len(new_fr)):
            new_fr[i] = new_fr[i][m:]
        for x in range(len(new_fr)):
            for y in range(len(new_fr[x])):
                if new_fr[x][y] == "+":
                    adj = []
                    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                        u, v = x + dx, y + dy
                        if 0 <= u < len(new_fr) and 0 <= v < len(new_fr[u]) and new_fr[u][v] != ' ':
                            adj.append((dx, dy))
                    if len(adj) == 2:
                        dx1, dy1 = adj.pop()
                        dx2, dy2 = adj.pop()
                        if dx1 == dx2 == 0:
                            new_fr[x][y] = '-'
                        elif dy1 == dy2 == 0:
                            new_fr[x][y] = '|'
                        
        return '\n'.join(''.join(row).rstrip() for row in new_fr)  


    res = []
    while len(spaces) > 0:
        x, y = spaces.pop()
        seen, fr = get_component(x, y)
        for u, v in seen:
            spaces.discard((u, v))
        if all(0 < a < n - 1 and 0 < b < m - 1 for a, b in seen):
            res.append(clean_frontier(fr))
    return res

def break_evil_pieces(shape):
    _shape = scale(shape)
    _pieces = break_pieces(_shape)
    return [downscale(piece) for piece in _pieces]


p = '''+-----------------+---+---------------------------------+---+---------------------------------+---+-----------------+
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 +-+-+-+                               |   |                                 |   |                 |
|                 | | | |                               |   |                                 |   |                 |
|                 +-+-+-+                               |   |                                 |   |                 |
|                 | | | |                               |   |                                 |   |                 |
|                 +-+-+-+                           +---+   +---+                         +---+   +---+             |
|                 | | | |                           |           |                         |           |             |
|                 +-+-+-+                           |           |                         |           |             |
|                       |                           |           |                         |           |             |
+-----------------------+             +-------------+           +-------------------------+           +-------------+
|                       |             |                                                                             |
|   +-----------------+ |             |                                                                             |
|   |                 | |             |                                                                             |
+---+       +-------+ | |             +-----------------------------------------------------------------------------+
|           |       | | |                                                                                           |
|           | +---+ | | |                                                                                           |
|           | |   | | | |                                                                                           |
|           | |   +-+ | |                                                                                           |
|           | |       | |                                                                                           |
|           | +-------+ |                                                                                           |
|           |           |                                                                                           |
|           +-----------+                                                                                           |
|                                                                                                                   |
|                 +---+                                 +---+                                 +---+                 |
|                 |   |                                 |   |                                 |   |                 |
|                 +---+                                 |   |                                 |   |                 |
|                                                       |   |                                 |   |                 |
|         +-------------+                               |   |                                 |   |                 |
|         |             |                               |   |                                 |   |                 |
|         | +---------+ |                   +-----------+   |                                 |   |                 |
|         | |         | |                   |               |                                 |   |                 |
|         | | +-----+ | |                   | +---+         |                             +---+   +---+             |
|         | | |     | | |                   | |   |         |                             |           |             |
|         | | | +-+ | | |                   | |   |     +---+                             |           |             |
|         | | | | | | | |                   | |   |     |                                 |           |             |
+-+       | | | +-+ | | |             +-----+ |   +-----+         +-----------------------+           +-------------+
| |       | | | |   | | |             |       |                   |                                                 |
| |       | | | +---+ | |             |       |             +-----+                                                 |
| |       | | |       | |             |       |             |                                                       |
+-+       | | +-------+ |             +-------+     +-------+       +-----------------------------------------------+
|         | |           |                           |               |                                               |
|         | +---+-+-----+                           |               |                                               |
|         |     | |                                 |               |                                               |
| +-------+-----+ |                                 +---+   +-------+                                               |
| |               |                                     |   |                                                       |
| +---------------+                                     |   |                                                       |
|                                                       |   |                                                       |
|                                                       |   |                                                       |
|                                                       |   |                                                       |
|                 +---+                                 |   |                                 +---+                 |
|                 |   |                                 |   |                                 |   |                 |
|                 +---+                                 +---+                                 +---+                 |
|                                                                                                                   |
|                                               +-------------+                                                     |
|                                               |             |                                                     |
|                                               | +---------+ |                                                     |
|                                               | |         | |                                                     |
|                                               | | +-----+ | |                                                     |
|                                               | | |     | | |                                                     |
|               +---------+                     | | | +-+ | | |                                                     |
|               |         |                     | | | | | | | |                                                     |
+-+             | +-----+ |     +-+-----+       | | | +-+ | | |             +---------------------------------------+
| |             | |     | |     | |     |       | | | |   | | |             |                                       |
| |             | | +-+ | |     | |     |       | | | +---+ | |             |                                       |
| |             | | | | | |     | |     |       | | |       | |             |                                       |
+-+             | | +-+ | |     +-+-----+       | | +-------+ |             +-------------+           +-------------+
|               | |     | |                     | |           |                           |           |             |
|               | +-----+ |                     | +---+-+-----+                           |           |             |
|               |         |                     |     | |                                 |           |             |
|               +---------+             +-------+-----+ |                                 +---+   +---+             |
|                                       |               |                                     |   |                 |
|                                       +---------------+                                     |   |                 |
|                                                                                             |   |                 |
|                                                                                             |   |                 |
|                                                                                             |   |                 |
|                 +---+                                 +---+                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 +---+                                 +---+                                 +---+                 |
|                 |   |                                                                                             |
|     +-----------+   |         +-+                                                                                 |
|     |               |         | |                                                                                 |
|     +---+-+---------+         +-+                                                                                 |
|         | |                                                                                                       |
|         +-+                                                                                                       |
|         | |                                                                                                       |
|         | |                                                                                                       |
|         | |                                                                                                       |
+-+       | +---------------------------+                                   +---------------------------------------+
| |       |                             |                                   |                                       |
| |       |                             |                                   |                                       |
| |       |                             |                                   |                                       |
+-+       +-------+   +-----------------+                                   +-------------+           +-------------+
|                 |   |                                                                   |           |             |
|                 |   |                                                                   |           |             |
|                 |   |                                                                   |           |             |
|                 |   |                                                                   +---+   +---+             |
|                 |   |                                                                       |   |                 |
|                 |   |                                                                       |   |                 |
|                 |   |                                                                       |   |                 |
|                 |   |                                                                       |   |                 |
|                 |   |                                                                       |   |                 |
|                 |   |                                 +---+                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 +---+                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|     +-----------+   |         +-+                     |   |                                 |   |                 |
|     |               |         | |                     |   |                                 |   |                 |
|     +---+-+---------+         +-+         +-----------+   |                                 |   +-----------+     |
|         | |                               |               |                                 |               |     |
|         +-+                               | +---+         |                                 |         +---+ |     |
|         | |                               | |   |         |                                 |         |   | |     |
|         | |                               | |   |     +---+                                 +---+     |   | |     |
|         | |                               | |   |     |                                         |     |   | |     |
+-+       | +-------------------------------+ |   +-----+         +---------------------+         +-----+   | +-----+
| |       |                                   |                   |                     |                   |       |
| |       |                                   |             +-----+                     +-----+             |       |
| |       |                                   |             |                                 |             |       |
+-+       +-------+   +-----------------------+     +-------+       +-----------------+       +-------+     +-------+
|                 |   |                             |               |                 |               |             |
|                 |   |                             |               |                 |               |             |
|                 |   |                             |               |                 |               |             |
|                 |   |                             +---+   +-------+                 +-------+   +---+             |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
|                 |   |                                 |   |                                 |   |                 |
+-----------------+---+---------------------------------+---+---------------------------------+---+-----------------+'''

# sol = break_pieces(p)
# np = len(sol)
# print("Num sol:", np)
# for r in sol:
#     print(r)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: