Advertisement
OPiMedia

sierpinski.py

Dec 19th, 2021
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. """
  2. Generation simple d'un triangle de Sierpinski avec une méthode aléatoire.
  3. """
  4.  
  5. import random
  6.  
  7. x0, y0 = 0, 0
  8. x1, y1 = -100, 100
  9. x2, y2 = 100, 100
  10.  
  11. sommets = ((x0, y0), (x1, y1), (x2, y2))
  12.  
  13. x, y = 0, 0
  14.  
  15. with open('out.txt', 'w') as fichier:
  16.     for _ in range(100000):
  17.         i = random.randint(0, 2)
  18.         x = (sommets[i][0] + x) / 2
  19.         y = (sommets[i][1] + y) / 2
  20.         print(f"{x} {y}", file=fichier)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement