Advertisement
here2share

# Tk_Sierpinski_Triangle_Random.py

Dec 22nd, 2021
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # Tk_Sierpinski_Triangle_Random.py
  2.  
  3. from Tkinter import *
  4. import random, time
  5.  
  6. ww = 400
  7. hh = 400
  8. root = Tk()
  9. root.title("Tk Sierpinski Triangle Random")
  10. root.geometry("%dx%d+0+0"%(ww,hh))
  11.  
  12. canvas = Canvas(root, width=ww, height=hh)
  13. canvas.pack()
  14.  
  15. x0, y0 = 200, 50
  16. x1, y1 = 50, 300
  17. x2, y2 = 350, 300
  18.  
  19. sierpinski = ((x0, y0), (x1, y1), (x2, y2))
  20.  
  21. x, y = 0, 0
  22.  
  23. for _ in range(100000):
  24.     i = random.randint(0, 2)
  25.     x = (sierpinski[i][0] + x) / 2
  26.     y = (sierpinski[i][1] + y) / 2
  27.     canvas.create_rectangle((x,y,x,y), fill='black', outline='')
  28.     canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement