1

Circles

This my program using turtle to draw the circle target:

import turtle

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)

The code makes a moving curve, but I want the circle to be drawn at once.

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
Sh Alzoubi
  • 13
  • 1
  • 4
  • 1
    Does this help? https://stackoverflow.com/questions/16119991/how-to-speed-up-pythons-turtle-function-and-stop-it-freezing-at-the-end?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – LangeHaare May 08 '18 at 16:49
  • 1
    If you don't want animation, you can use `turtle.speed(0)` to make drawing happen instantly. – Håken Lid May 08 '18 at 17:27
  • See example here: https://repl.it/@haakenlid/Turtletarget – Håken Lid May 08 '18 at 17:33

2 Answers2

0

The circle() method draws a circle, but the dot() method stamps one out. However, the dot() method doesn't have a separate line and fill concept and tends to overwrite itself, so we have to handle it carefully:

import turtle

def origin_circle(turtle, radius):
    turtle.dot(radius + 2, 'black')
    turtle.dot(radius, 'white')

for radius in range(200, 0, -40):
    origin_circle(turtle, radius)

turtle.hideturtle()

turtle.mainloop()

enter image description here

Alternatively, we could stamp out circular cursors ourselves:

import turtle

def origin_circle(turtle, radius):
    turtle.shapesize(radius)
    turtle.stamp()

turtle.shape('circle')
turtle.color('black', 'white')

for radius in range(10, 0, -2):
    origin_circle(turtle, radius)

turtle.hideturtle()

turtle.mainloop()

But this doesn't produce as pleasing a result:

enter image description here

Of course, we can always cheat and use turtle.speed('fastest'), or better yet, turn tracing off altogether:

import turtle

def origin_circle(turtle, radius):
    turtle.penup()
    turtle.sety(-radius)
    turtle.pendown()
    turtle.circle(radius, steps=90)

turtle.tracer(False)

for radius in range(20, 120, 20):
    origin_circle(turtle, radius)

turtle.hideturtle()

turtle.tracer(True)

turtle.mainloop()

But the result still won't look as nice as the turtle.dot() approach, even if you bump up the steps parameter of turtle.circle():

enter image description here

for the first code how to add an arrow on the top of each curve, one at down of each curve?

This is easier done modifying my third example as we can more easily draw semicircles and stamp the cursor. I'm using a custom cursor for arrow alignment across circles purposes:

import turtle

def origin_circle(turtle, radius):
    turtle.penup()
    turtle.sety(-radius)
    turtle.pendown()

    turtle.stamp()
    turtle.circle(radius, extent=180, steps=45)
    turtle.stamp()
    turtle.circle(radius, extent=180, steps=45)

turtle.addshape("pointer", ((0, 0), (5, -4), (0, 4), (-5, -4)))
turtle.shape("pointer")

turtle.tracer(False)

for idx, radius in enumerate(range(20, 120, 20), start=0):
    origin_circle(turtle, radius)

turtle.hideturtle()

turtle.tracer(True)

turtle.mainloop()

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81
-1
import turtle
ab=turtle.Turtle()
ab.speed(0)
import turtle

def zielscheibe(ringe=10):
    if ringe<1 or ringe>1000:
        ab.write('Bitte eine Zahl zwischen 1 und 1000 eingeben')
        return
    ab.pu()
    ab.goto(300,0)
    ab.seth(90)
    x=300/ringe
    for n in range(ringe):
        ab.pd()
        if n ==ringe-1:
            ab.color('black')
        elif n %2==0:
            ab.color('red')
        else:
            ab.color('white')
        ab.begin_fill()
        ab.circle(300-x*n)
        ab.end_fill()
        ab.pu()
        ab.left(90)
        ab.fd(x)
        ab.right(90)

zielscheibe(10)
turtle.mainloop()