j0h

inline_ascii_art_mirror

j0h
Dec 31st, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.60 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # horizontal character mirroring
  3.  
  4. a = r"""
  5.                      .-.
  6.                     (   )
  7.                      '-'
  8.                      J L
  9.                      | |
  10.                     J   L
  11.                     |   |
  12.                    J     L
  13.                  .-'.___.'-.
  14.                 /___________\\
  15.            _.- '           'E \._
  16.          .'                       '.
  17.        J                            '.
  18.       F                               L
  19.      J                                 J
  20.     J                                   '
  21.     |                                   L
  22.     |                                   |
  23.     |                                   |
  24.     |                                   J
  25.     |                                    L
  26.     |                                    |
  27.     |             ,.___ ______   ___....--._
  28.     |           ,'     '        '           '-._
  29.     |          J           _____________________'-.
  30.     |         F         .-'   '-88888-'    'Y8888b.'.
  31.     |         |       .'         'P'         '88888b \\
  32.     |         |      J       #     L      #    q8888b L
  33.     |         |      |             |           )8888D )
  34.     |         J      \            J           d8888P P
  35.     |          L      '.         .b.         ,88888P /
  36.     |           '.      '-.___,o88888o.___,o88888P'.'
  37.     |             '-.__________________________..-'
  38.     |                                    |
  39.     |         .-----.........____________J
  40.     |       .' |       |      |       |
  41.     |      J---|-----..|...___|_______|
  42.     |      |   |       |      |       |
  43.     |      Y---|-----..|...___|_______|
  44.     |       '. |       |      |       |
  45.     |         ''-------:....__|______.J
  46.     |                                  |
  47.      L___                              |
  48.          `""----...______________...---'
  49.  
  50. """
  51.  
  52. def mirror(value: str) -> str:
  53.     value = value.lstrip("\n").rstrip("\n")
  54.     swap = str.maketrans({
  55.         "/": "\\",
  56.         "\\": "/",
  57.         "(": ")",
  58.         ")": "(",
  59.         "[": "]",
  60.         "]": "[",
  61.         "{": "}",
  62.         "}": "{",
  63.         "<": ">",
  64.         ">": "<",
  65.         "L": "J",
  66.         "J": "L",
  67.     })
  68.  
  69.     lines = value.splitlines()
  70.     w = max((len(line) for line in lines), default=0)
  71.  
  72.     # pad so whitespace mirrors too, then swap directional chars, then reverse
  73.     return "\n".join(line.ljust(w).translate(swap)[::-1] for line in lines)
  74.  
  75.  
  76. def mirror_inline(value: str, *, gap: int = 2, seam: str = "") -> str:
  77.     """
  78.    Return: original + gap + (optional seam) + gap + mirrored
  79.    gap: spaces between halves (and around seam if seam provided)
  80.    seam: optional string to put between halves (e.g. " | ")
  81.    """
  82.     value = value.lstrip("\n").rstrip("\n")
  83.  
  84.     # same swap map used by mirror()
  85.     swap = str.maketrans({
  86.         "/": "\\",
  87.         "\\": "/",
  88.         "(": ")",
  89.         ")": "(",
  90.         "[": "]",
  91.         "]": "[",
  92.         "{": "}",
  93.         "}": "{",
  94.         "<": ">",
  95.         ">": "<",
  96.         "L": "J",
  97.         "J": "L",
  98.     })
  99.  
  100.     lines = value.splitlines()
  101.     w = max((len(line) for line in lines), default=0)
  102.  
  103.     out = []
  104.     spacer = " " * gap
  105.     mid = (spacer + seam + spacer) if seam else spacer
  106.  
  107.     for line in lines:
  108.         left = line.ljust(w)
  109.         right = left.translate(swap)[::-1]
  110.         out.append(left + mid + right)
  111.  
  112.     return "\n".join(out)
  113.  
  114. print(mirror_inline(a, gap=2, seam=" HAPPY NEW YEAR HUMAN"))
  115. #mirrored = mirror(a)
  116. #print(mirrored)
  117. #print(a)
  118. #print(mirror_inline(a, gap=4))
  119.  
Advertisement
Add Comment
Please, Sign In to add comment