Guest User

Untitled

a guest
Oct 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. #
  3. # Fill a circle with 0 and 1's
  4. # The circle is made of half as many lines as it is made of columns.
  5. # This way, it usually appears round (with most terminal fonts at least).
  6. # Accept the circle's width-radius as argument. See the default radius r, below.
  7.  
  8. r = 15
  9. from sys import argv
  10. if len(argv) > 1:
  11. r = int(argv[1])
  12.  
  13. import random
  14.  
  15. def rand01generator():
  16. while True:
  17. r = random.randrange(2 ** 32)
  18. for i in range(32):
  19. yield 1 & r >> i
  20.  
  21. class Circle:
  22. def __init__(self, r):
  23. self.r = r
  24. def __contains__(self, point):
  25. x, y = point
  26. return x ** 2 + y ** 2 <= self.r ** 2
  27.  
  28. c = Circle(r)
  29.  
  30. g = rand01generator()
  31.  
  32.  
  33. text = []
  34.  
  35. for y in range(r):
  36. line = []
  37. for x in range(2*r):
  38. if (x + 0.5 - r, 2 * y + 1 - r) in c:
  39. line.append(str(next(g)))
  40. else:
  41. if x <= r:
  42. line.append(" ")
  43. text.append("".join(line))
  44.  
  45. print("\n".join(text))
  46.  
  47. example_output = """
  48. 0101010011
  49. 011110000011100101
  50. 1110111010111111011011
  51. 00000000101011000010100100
  52. 1101011100101001001110110100
  53. 1101110101110101100101111111
  54. 010101001110010111001011111101
  55. 101100011100101101110011000111
  56. 110111000110000010000010001101
  57. 0010100110001000110010010000
  58. 0100110101000100011000100111
  59. 11100100010011000000001000
  60. 1001010101101101010101
  61. 011111010101101011
  62. 1011110000
  63. """
Add Comment
Please, Sign In to add comment