Hello! Tell me, please, how to draw a spiral? Wrote such a parody of the code

  from tkinter import *

 root = Tk ()

 canvas = Canvas (root, width = 300, height = 300)
 canvas.pack ()
 step = 10
 p = [145, 145, 155, 155]
 iters = 0
 canvas.create_arc (p [0], p [1], p [2], p [3], start = 0, extent = 180, style = ARC)

 while p [0]> 10:
     if (iters% 2):
         canvas.create_arc (p [0] - step, p [1] - step, p [2], p [3],
                           start = 0, extent = 180, style = ARC)
         p [0], p [1] = p [0] - step, p [1] - step
     else:
         canvas.create_arc (p [0], p [1], p [2] + step, p [3] + step,
                           start = 0, extent = -180, style = ARC)
         p [2], p [3] = p [2] + step, p [3] + step
     iters + = 1
 root.mainloop () 

At the output, I get this:

Spiral

The question is how to get rid of this gap?

I tried to play with the arguments start and extent, but this did not give any qualitative result, because the two parts did not coincide with each other, i.e. something like this:

Spiral2

^ Here I entered the values ​​from the bald, not pixel by pixel.

Has anyone encountered such a problem?

    1 answer 1

    At each step, you need to expand the ellipse (of which the arc is drawn) up and down equally. If you do as you do now, then the centers of even and odd ellipses will move up and down from the horizontal axis, which is why the gap between the top and bottom is obtained. Work code:

    from tkinter import * root = Tk() canvas = Canvas(root, width=300, height=300) canvas.pack() step = 10 p = [145, 145, 155, 155] iters = 0 canvas.create_arc(*p, start=0, extent=180, style=ARC) while p[0] > step: p[1] -= step/2 # расширение вниз p[3] += step/2 # расширение вверх if iters % 2: p[0] -= step # расширение и сдвиг левой границы влево canvas.create_arc(*p, start=0, extent=180, style=ARC) else: p[2] += step # расширение и сдвиг правой границы вправо canvas.create_arc(*p, start=0, extent=-180, style=ARC) iters += 1 root.mainloop() 

    screenshot

    • Thank you very much for the explanation! - Javed