user3007424
user3007424

Reputation: 1

How do I draw a circle looping around with a circle in the middle at the end using python turtle?

The shape should look like this image Image of Circle Loop

This should be a simple hw assignment, so if you are using any advanced math or anything you're probably not doing it correctly. It should only involve simple functions like left, right, forward, penup, pendown, etc.

I really need help finishing this. This is the code I have down so far, but the circle is not moving correctly.

# Repeating Circle Loop

import turtle

turtle.colormode(255)

window = turtle.Screen()
window.title('Circle Loop')
window.bgcolor('black')

red, green, blue = 255, 255, 0

draw = turtle.Turtle()
draw.color(red, green, blue)

radius = 50

for i in range(12):
    draw.circle(radius)
    draw.penup()
    draw.setposition(i * - 10, 0)
    draw.left(30)
    draw.pendown()
    green = green - 20
    blue = blue + 20
    draw.color(red, green, blue)

window.mainloop()

Upvotes: 0

Views: 8985

Answers (3)

nino_701
nino_701

Reputation: 692

You may be interested in some code like this:

from math import sin, cos, pi
from turtle import *

tracer(2,1)

def myCircle(x, y, r, c1, c2): # draw a circle with radius r in the point (x,y)
            up(); goto(x+r, y) ; down()
            color(c1, c2)
            begin_fill()
            for i in range(361):
                a = x + r*cos(pi*i/180)
                b = y + r*sin(pi*i/180)
                goto(a, b)
            end_fill()

c1, c2 = 'red', 'blue'
for i in range(5):
    myCircle(0, 0, 200-i*40,c1, c2 )
    c1, c2 = c2, c1

Upvotes: 1

user3014273
user3014273

Reputation: 31

Try this loop:

for i in range(12):
    draw.circle(radius)
    draw.penup()
    draw.left(180)
    draw.circle(radius,30)
    draw.right(180)
    draw.pendown()

Upvotes: 0

user2357112
user2357112

Reputation: 280291

Write a subroutine to draw a circle. Then, write another subroutine that draws a circle, curving in the opposite direction, and calls the first subroutine to draw additional circles around the inner circle at regular intervals.

Upvotes: 1

Related Questions