#halving_root2.py # 1xRoot2, chop of unit square, spiral down. Cf. A-series paper. import math from ezgraphics import GraphicsWindow width = int(input("Enter width of graphics window: ")) height = width / 1.41421356 win = GraphicsWindow(width,height) #create a drawing window canvas = win.canvas() x_left = 1 x_right = width y_down = 1 y_up = height canvas.drawRectangle(0,0,width-1,height-1) x = y = 0 for i in range(1,2*int(math.log2(width))): if i%2 == 1: if i%4 == 1: #1,5,9,... x_left += int((x_right-x_left) / 1.41421356) canvas.setColor("black") canvas.drawLine(x_left,y_down, x_left,y_up) canvas.setColor("yellow") canvas.drawLine(x,y, x_left,y_up) x = x_left y = y_up else: #3,7,11,... x_right -= int((x_right-x_left) / 1.41421356) canvas.setColor("black") canvas.drawLine(x_right,y_down, x_right,y_up) canvas.setColor("yellow") canvas.drawLine(x,y, x_right,y_down) x = x_right y = y_down else: if i%4 == 2: #2,6,10,... y_up += int((y_down-y_up) / 1.41421356) canvas.setColor("black") canvas.drawLine(x_left,y_up, x_right,y_up) canvas.setColor("yellow") canvas.drawLine(x,y, x_right,y_up) x = x_right y = y_up else: #4,8,12,... y_down -= int((y_down-y_up) / 1.41421356) canvas.setColor("black") canvas.drawLine(x_left,y_down, x_right,y_down) canvas.setColor("yellow") canvas.drawLine(x,y, x_left,y_down) x = x_left y = y_down #print(x_left,x_right," ",y_down,y_up) print("(1/root2)^",i,"=",(1/1.41421356)**i) print("Look at the graphics window")