#Sierpinski.py # in a triangle, at any starting point, go randomly to halfway to one of the corners, #repeatedly. Random mess appears? import random from ezgraphics import GraphicsWindow width = int(input("Enter width of graphics window: ")) height = int(input("Enter height of graphics window: ")) num_pts = int(input("Enter number of points (try 10000): ")) print("In the graphics window click 3 vertices of a triangle, then a starting point") win = GraphicsWindow(width,height) win.setTitle("Sierpinski triangle/gasket") win.showStatus() win.setStatus("Click 3 vertices of a triangle, then a starting point") canvas = win.canvas() canvas.drawText(10, 10, "Click 3 vertices of a triangle, then a starting point") canvas.setFill("black") vertices = [] for pt in range(3): vertices.append(win.getMouse()) canvas.drawOval(vertices[pt][0]-1,vertices[pt][1]-1,3,3) ''' x1,y1 = win.getMouse() canvas.drawOval(x1-1,y1-1,3,3) x2,y2 = win.getMouse() canvas.drawOval(x2-1,y2-1,3,3) x3,y3 = win.getMouse() canvas.drawOval(x3-1,y3-1,3,3) ''' x,y = win.getMouse() canvas.drawPoint(x,y) for i in range(num_pts): which_pt = random.choice([0,1,2]) #go halfway to random vertex: x = (x + vertices[which_pt][0]) / 2 y = (y + vertices[which_pt][1]) / 2 ''' if which_pt == 1: #go halfway to pt 1 x = (xp + x1) / 2 y = (yp + y1) / 2 elif which_pt == 2: #go halfway to pt 2 x = (xp + x2) / 2 y = (yp + y2) / 2 else: #go halfway to pt 3 x = (xp + x3) / 2 y = (yp + y3) / 2 ''' canvas.drawPoint(x,y) win.wait()