Question

I am trying to draw a target like this: like this
(source: newscientist.com)

using turtle.

The problem is turtle includes the origin as part of the graph, as opposed to the origin being in the center. My question is, how do I get turtle draw a circle AROUND the origin rather than include it?

import turtle

radius = 100
turtle.speed(0)

for rings in range(10):


    turtle.circle(radius)
    radius += 10
Était-ce utile?

La solution

import turtle

radius = 100
turtle.speed(0)

for rings in range(10):
    turtle.penup()
    turtle.goto(0, -radius)
    turtle.pendown()
    turtle.circle(radius)
    radius += 10

Autres conseils

It's nicer to use radius as the loop variable

import turtle

turtle.speed(0)

for radius in range(100, 200, 10):
    turtle.penup()
    turtle.goto(0, -radius)
    turtle.pendown()
    turtle.circle(radius)

Then you might wish to define a function

import turtle

turtle.speed(0)

def origin_circle(turtle, radius):
    turtle.penup()
    turtle.goto(0, -radius)
    turtle.pendown()
    turtle.circle(radius)

for radius in range(100, 200, 10):
    origin_circle(turtle, radius)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top