#halvingSquares.py #each smaller square is half the area of the previous from ezgraphics import GraphicsWindow import math sqr = int(input("Enter square size of graphics window: ")) win = GraphicsWindow(sqr,sqr) canvas = win.canvas() x = y = 0 width = sqr # SQR*(1/root2)**x > 4 pixels width... solve: # x > ln4/ln(1/root2) - lnSQR/ln(1/root2) # x > -4 - lnSQR/-.34657 max_loops = -4 - math.log(sqr)/-.34567 for i in range(1,int(max_loops)+2): x += (width*(1-1/math.sqrt(2))) / 2 y += (width*(1-1/math.sqrt(2))) / 2 print("width:",int(width),"area:",int(width*width),int(x),int(y)) width = (1/math.sqrt(2))**i * sqr canvas.drawRectangle(x,y, width,width) print("Look at the graphics window")