Advertisement
makispaiktis

Visualizing 3000 digits of 'pi'

May 18th, 2022 (edited)
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import turtle
  2. from math import pi
  3. try:
  4.     # import version included with old SymPy
  5.     from sympy.mpmath import mp
  6. except ImportError:
  7.     # import newer version
  8.     from mpmath import mp
  9.  
  10. # 1. Decimal places = 1000
  11. mp.dps = 3 * 10**3
  12. _PI_ = mp.pi
  13. PI = [int(element) for element in str(_PI_) if element != "."]
  14. print(PI)
  15.  
  16. # 2. Settings
  17. turtle.speed(100)
  18. turtle.color("red")
  19. walk = 10
  20. basis = 10
  21. angle = 360 / basis
  22. counter = 0
  23.  
  24. # Algorithm
  25. for digit in PI:
  26.     print("Counter = " + str(counter) + ", digit = " + str(digit) + ", angle = " + str(digit * angle))
  27.     turtle.left(digit * angle)
  28.     turtle.forward(walk)
  29.     counter += 1
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement