2016-04-16 4 views
-1

Я пытаюсь нарисовать фигуру, которая выглядит примерно так:Цифры с черепахой питона

example drawing

Как я могу это сделать?

Также как рисовать концентрические круги без использования модуля circle Python? До сих пор, у меня есть следующий код:

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() 

ответ

0

Я считаю, что этот код должен ответить на ваши вопросы:

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 он работал. –

Смежные вопросы