Guest User

Untitled

a guest
Jul 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. from graphics import *
  2.  
  3.  
  4.  
  5. def sierpinskiT(points,level,win, label=0):
  6.  
  7. colormap = ['blue','red','green','white'] #,'yellow','violet','orange']
  8.  
  9.  
  10.  
  11. p = Polygon(points)
  12.  
  13. p.setFill(colormap[level])
  14.  
  15. p.draw(win)
  16.  
  17. time.sleep(2)
  18.  
  19.  
  20.  
  21. if level > 0:
  22.  
  23. # sol sierpinski
  24.  
  25. sierpinskiT([points[0],
  26.  
  27. getMid(points[0],points[1]),
  28.  
  29. getMid(points[0],points[2])],level-1,win,label=2)
  30.  
  31. # ust sierpinski
  32.  
  33. sierpinskiT([getMid(points[0],points[1]),
  34.  
  35. points[1],
  36.  
  37. getMid(points[1],points[2])],level-1,win,label=1)
  38.  
  39.  
  40.  
  41. # sag sierpinski
  42.  
  43. sierpinskiT([getMid(points[0],points[2]),
  44.  
  45. getMid(points[1],points[2]),
  46.  
  47. points[2]],level-1,win,label=3)
  48.  
  49.  
  50.  
  51. def getMid(p1,p2):
  52.  
  53. return Point( ((p1.getX()+p2.getX()) / 2.0),
  54.  
  55. ((p1.getY()+p2.getY()) / 2.0) )
  56.  
  57.  
  58.  
  59. if __name__ == '__main__':
  60.  
  61. win = GraphWin('st',500,500)
  62.  
  63. win.setCoords(20,-10,80,50)
  64.  
  65. myPoints = [Point(25,0),Point(50,43.3),Point(75,0)]
  66.  
  67. sierpinskiT(myPoints,2,win,label=0)
Add Comment
Please, Sign In to add comment