2017-10-08 125 views
1

我想用烏龜畫這張照片。Python。學習烏龜圖形

這是我得到的ATM:

import turtle 


    def animal(): 
     turtle.speed(1) 
     turtle.pencolor('black') 
     turtle.up() 
     turtle.goto(-180, -180) 
     turtle.down() 
     turtle.lt(180) 
     turtle.circle(-200, 180) 
     turtle.lt(90) 
     turtle.circle(50, 220) 
     turtle.done() 

所以,問題是如何繪製體半圓後得出鼠標的耳朵。因爲在我的代碼中,鼠標耳朵與身體相交。如果不猜測正確的座標並返回到耳朵開始點之後,是否有任何好方法? enter image description here

回答

1

什麼好辦法做到這一點無需猜測正確的座標和後 迴歸到了耳點開始

此代碼應該做的,您的要求兩件事:1)繪製耳朵而不必知道停止在哪裏; 2)返回到耳朵開始畫:

import turtle 

def animal(): 
    turtle.up() 
    turtle.goto(-180, 180) 
    turtle.lt(90) 
    turtle.down() 
    turtle.fillcolor('gray45') 
    turtle.begin_fill() 
    turtle.circle(75) 
    turtle.end_fill() 
    turtle.lt(90) 
    turtle.fillcolor('white') 
    turtle.begin_fill() 
    turtle.circle(170, 180) 
    turtle.end_fill() 
    turtle.circle(170, -180) 

animal() 

turtle.done() 

enter image description here