2017-10-08 127 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