Link to home
Start Free TrialLog in
Avatar of opensourcenija
opensourcenija

asked on

looping circles in python

I am trying to loop a circle in python something like the picture attached below


def drawPatch1(win,colour):
        for i in range(15):
            dia=20
            dia1 =dia + 20
            circ= Circle(Point(100,200), dia)
            circ.setOutline(colour)
            circ.draw(win)

Open in new window

circe.jpg
Avatar of pepr
pepr

I do not know your code around.  However, from a simple geometry point of view, you have to change both diameter and position of the center.  As the circles should touch, you have to move the point to the half of the diameter from the touching point.

Also, you have to set dia = 20 before the loop (the line 3 in front of the line 2 and fix the indentation); otherwise, you are setting 20 again and again.  You do not need the dia1 variable.  Just remove the line 4 and put the line after 7 (with the correct indentation):

dia = dia + 20

Then it should draw 15 concentric circles.  After making it working, introduce a new y variable for the center point -- in front of the loop, just after dia initialization.  Initialize the y to the coordinates of touching point plus dia/2.  Fixt the position of y as the last line of the loop (y = ytouch + dia/2).
ASKER CERTIFIED SOLUTION
Avatar of Kusala Wijayasena
Kusala Wijayasena
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of opensourcenija

ASKER

thanks the solution offered by kusala worked