2016-04-16 7 views
-1

Ich versuche, eine Figur zu zeichnen, die etwa wie folgt aussieht:Figuren mit Python Schildkröte

example drawing

Wie kann ich das tun?

Wie kann ich auch konzentrische Kreise ohne Pythons circle Modul zeichnen? Bisher habe ich den folgenden Code:

import turtle 

def window(ttl,colr): 
    wn=turtle.Screen() 
    wn.title(ttl) 
    wn.bgcolor(colr) 
    return wn 

def turtles(siz,col,shp): 
    tl=turtle.Turtle() 
    tl.pensize(siz) 
    tl.color(col) 
    tl.shape(shp) 
    return tl 

def square(sz): 
    for i in range(4): 
     trtl.fd(sz) 
     trtl.rt(90) 
    trtl.pu() 
    trtl.rt(90) 
    trtl.fd(sz+20) 
    trtl.lt(90) 
    trtl.pd() 

dg=window('Concentric Square','lightgreen') 
trtl=turtles('3','blue','turtle') 
size=20 
for i in range(5): 
    square(size) 
    size=size+20 
dg.listen() 
dg.mainloop() 

Antwort

0

ich diesen Code glauben sollte Ihre Fragen beantworten:

import turtle 

def window(ttl,colr): 
    wn=turtle.Screen() 
    wn.title(ttl) 
    wn.bgcolor(colr) 
    return wn 

def turtles(siz,col,shp): 
    tl=turtle.Turtle() 
    tl.pensize(siz) 
    tl.color(col) 
    tl.shape(shp) 
    return tl 

def square(sz): 
    for i in range(4): 
     trtl.fd(sz) 
     trtl.rt(90) 
    trtl.pu() 
    trtl.rt(180)   #Turns around 
    for x in range(2): #Repeat twice 
     trtl.fd(10)  #Moves half the size of 20 forward (away from the square) 
     trtl.rt(90)  #Turns right 
    trtl.pd() 

def draw_circle(): 
    z=120    #You can change this to make the circle more choppy/finer and larger/smaller 
    for x in range(z): 
     trtl.fd(5)  #You can change this to make the circle larger/smaller 
     trtl.rt(360/z) 

dg=window('Concentric Square','lightgreen') 
trtl=turtles('3','blue','turtle') 
trtl.speed(0) 
size=20 
for i in range(5): 
    square(size) 
    size=size+20 

trtl.pu() 
trtl.fd(300) 
trtl.pd() 
draw_circle() 

dg.listen() 
dg.mainloop() 
+0

Thnx es funktionierte. –