Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. def circle(chars):
  2. test = """
  3.  
  4. @@@@@@@@@@@@@
  5. @@ @@
  6. @@ @@
  7. @@ @@
  8. @ @
  9. @ @
  10. @ @
  11. @ @
  12. @ @
  13. @ @
  14. @ @
  15. @ @
  16. @ @
  17. @ @
  18. @ @
  19. @ @
  20. @@ @@
  21. @@ @@
  22. @@ @@
  23. @@@@@@@@@@@@@
  24.  
  25. """
  26.  
  27. #chars = "abcdefghijklmnopqrstuvwxyzABDEFGHIJKLMOPQRSTUVWXYZ1234567890,.<>?;'#:~[]{}$%^&*)(£!|"
  28. chars = chars.replace(" ", "¬")
  29.  
  30. def extract(chars, start, end):
  31. if end > len(chars):
  32. ext = chars[start:len(chars)]
  33. end -= len(chars)
  34. while end >= 0:
  35. ext += chars[:min(len(chars), end)]
  36. end -= len(chars)
  37. return ext
  38. else:
  39. return chars[start:end]
  40.  
  41. ci = 0
  42.  
  43. lines = [x for x in test.split("\n") if x.replace(" ", "") != ""]
  44. result = lines[:]
  45. for index in range(2):
  46. found_top = False
  47. reverse = index == 1
  48. for i, line in enumerate(lines):
  49. if index == 1:
  50. i = -(i+1)
  51. line = lines[i]
  52. front = ""
  53. while len(line) > 0 and line[0] == " ":
  54. front += " "
  55. line = line[1:]
  56. if len(front) == 1:
  57. reverse = (reverse == False)
  58. end = ""
  59. while len(line) > 0 and line[-1] == " ":
  60. end += " "
  61. line = line[:-1]
  62. if " " not in line: # top or bottom
  63. if not found_top: # bottom
  64. if index == 1: # going up
  65. result[i] = front + extract(chars, ci, ci+len(line))[::-1] + end
  66. ci = (ci + len(line)) % len(chars)
  67. elif index == 0: # going down
  68. result[i] = front + extract(chars, ci, ci+len(line)) + end
  69. ci = (ci + len(line)) % len(chars)
  70. found_top = True
  71. else:
  72. spl = [x for x in line.split(" ") if x != ""]
  73. right = spl[0]
  74. left = spl[1]
  75. middle = line[len(right):-len(left)]
  76. if index == 0: # going down
  77. block = extract(chars, ci, ci+len(right))
  78. if reverse:
  79. block = block[::-1]
  80. result[i] = middle + block + end
  81. ci = (ci + len(right)) % len(chars)
  82. else: # going up
  83. block = extract(chars, ci, ci + len(left))
  84. if reverse:
  85. block = block[::-1]
  86. result[i] = front + block + result[i]
  87. ci = (ci + len(left)) % len(chars)
  88.  
  89. return "```" + "\n".join(result).replace("¬", " ") + "```"
  90.  
  91. result(circle(" ".join(getargs())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement