I need help creating a python function that makes concentric circles. I already have a function that makes a circle(from the Python Programming book), so I thought I'd use a for loop; however, I'm not sure how. Here's what I have so far: (where 'number' is the number of circles, and 'distance' is the space between them)

def concentric (myTurtle,number,distance):
      for i in range(1,number):
           drawCircle(myTurtle,distance)
           myTurtle.up()
           myTurtle.left(90)
           myTurtle.forward(spacing)
           myTurtle.right(90)
           myTurtle.down()

Any and all help would be greatly appreciated!

Recommended Answers

All 8 Replies

See other thread of same topic.

I did take a look at the other thread, but I'm trying to make concentric circles using a different method. I came up with more to add to it:

def concentric(myTurtle,number,distance)
                  for i in range(0,number+1,distance):
                       for i in range(number):
                             drawCircle(myTurtle,distance)
                             myTurtle.up()
                             myTurtle.left(90)
                             myTurtle.forward(distance)
                             myTurtle.right(90)
                             myTurtle.down()

Using this myTurtle draws the number of circles I want and correctly spaces them, but all the circles remain the same size instead of becoming increasing bigger/smaller.

Check the post where I revealed how to make to consentric circles. What is different to your code? Is the radius changing or same?

from turtle import *
r=100 ## radius of current circle
a=20 ## separation

circle(r)
## separation walk pen up
up()
left(90)
fd(a)
right(90) ## restoring direction
down()

r-=a

circle(r)
mainloop()

You have nested loop with same index variable in them both. You are not showing enough effort.

Get something really running code and we can help with the last glitches.

Get program running, experiment. Try to do with your body the movements of the turtle.

Compare situation in the beginning of consecutive loops. What should change, what is changing. How do you know to stop? How are you getting users input or are able to cope with different inputs or parameters?

Start and do not give up. Do not be afraid of things not running first time and running wrong next time.

Here is a Python module turtle example of how to draw two concentric circles ...

import turtle as tu

# initial radius
radius = 100
# distance between circles
distance = 30

# pen up
tu.up()
# move pen to point x, y
# keeps the center of the circle at canvas center
tu.goto(0, -radius)
# pen down
tu.down()
tu.circle(radius)

# increase the radius value by distance
radius  += distance

# pen up
tu.up()
# move pen to point x, y
# keeps the center of the circle at canvas center
tu.goto(0, -radius)
# pen down
tu.down()
tu.circle(radius)

tu.done()

I leave it up to you to wrap the whole thing into a for loop to streamline coding and then into a function.

Can you mark solved or tell what is still unclear/post results?

Can you mark solved or tell what is still unclear/post results?

You did the person's homework, I doubt he/she will be back.

Thanks Tonyjv, you were right. There were a couple things I didn't think of , and that I needed to change, but now it works. Sorry about the late reply, I had something else I was working on. Again, thanks for all your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.