[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2214
  • Last Modified:

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
0
opensourcenija
Asked:
opensourcenija
1 Solution
 
peprCommented:
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
 
Kusala WijayasenaSoftware EngineerCommented:
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

Open in new window

0
 
opensourcenijaAuthor Commented:
thanks the solution offered by kusala worked
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now