Zeichnung Blume mit python turtle

Lerne ich Programmieren mit python (bezieht sich denke python 2) und bin überrascht, an einem Programm. Problem Erklärung: Python program to draw a symmetric flower after seeking the size of and number of petals from user.

Den code, mit dem ich kam ist unten, außer ich bin nicht in der Lage zu Holen Sie sich die Winkel zwischen den einzelnen Blütenblatt mathematisch Recht (Teil wo der code am Ende heißt es bob.lt(360/petal)). Kann mir jemand hier helfen?

import math
radius=int(input("What is the radius of the flower? "))
petals=int(input("How many petals do you want? "))
#radius=100
#petals=4


def draw_arc(b,r):  #bob the turtle,corner-to-corner length (radius) of petal (assume 60 degree central angle of sector for simplicity)
    c=2*math.pi*r #Circumference of circle
    ca=c/(360/60)  #Circumference of arc (assume 60 degree central angle of sector as above)
    n=int(ca/3)+1  #number of segments
    l=ca/n  #length of segment
    for i in range(n):
        b.fd(l)
        b.lt(360/(n*6))

def draw_petal(b,r):
    draw_arc(b,r)
    b.lt(180-60)
    draw_arc(b,r)

import turtle
bob=turtle.Turtle()

#draw_petal(bob,radius)

for i in range(petals):
    draw_petal(bob,radius)
    bob.lt(360/petals)

turtle.mainloop()

Zeichnung Blume mit python turtle
Richtige (Symmetrische)
Zeichnung Blume mit python turtle
Falsch (Asymmetrisch)

1) Kann Ihnen einen link zur Dokumentation der Turtle-Paket, das Sie importiert? 2) Welchen Unterschied sehen Sie zwischen dem Ergebnis, das aufgetreten ist, und das Ergebnis, das Sie erwartet hatten? I. e. wie wissen Sie, dass Sie sich nicht immer, der Winkel zwischen Blütenblätter mathematisch richtig? Es kann helfen, zu zeigen, eine Grafik.
Ich habe aktualisiert die ursprüngliche Frage mit den snaps von expectated Ausgang am Ende... die Blüte sollten symmetrisch sein. Die offizielle Dokumentation ist hier -> docs.python.org/3.1/library/turtle.html

InformationsquelleAutor njathan | 2017-02-16

Schreibe einen Kommentar