looping circles in python

Posted on 2009-12-19
Last Modified: 2013-11-13
I am trying to loop a circle in python something like the picture attached below

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

Open in new window

Question by:opensourcenija
    LVL 28

    Expert Comment

    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).
    LVL 11

    Accepted Solution

    I have written simple program to achieve your task. Just look at it

    (The graphics module that I have used is :

    from graphics import *
    def drawPatch1(win, colour):
    	for i in range(10):
    		radius = 100 - (i * 10)
    		circ = Circle(Point(150, 150 + (i * 10)), radius)
    win = GraphWin("Draw", 300, 300)
    drawPatch1(win, "red")
    win.getMouse() # Pause to view result

    Open in new window


    Author Comment

    thanks the solution offered by kusala worked

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: Swadhin
    Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now