Solved

# looping circles in python

Posted on 2009-12-19
1,705 Views
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)
``````
circe.jpg
0
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).
0

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 : http://mcsp.wartburg.edu/zelle/python/graphics.py)

-Kusala
``````from graphics import *

def drawPatch1(win, colour):

for i in range(10):

radius = 100 - (i * 10)

circ = Circle(Point(150, 150 + (i * 10)), radius)

circ.setOutline(colour)

circ.draw(win)

win = GraphWin("Draw", 300, 300)

win.setBackground("white")

drawPatch1(win, "red")

win.getMouse() # Pause to view result
``````
0

Author Comment

thanks the solution offered by kusala worked
0

## Featured Post

### Suggested Solutions

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 …