Python。学习海龟图形

2024-04-20 03:18:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用乌龟画这幅画。在

这是我在自动取款机上得到的:

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

所以问题是在画完身体半圆后,如何画出老鼠耳朵。因为在我的代码里,鼠标耳朵和身体相交。在不猜测正确的坐标并且回到ear的起始点之后,有没有什么好方法可以做到呢? enter image description here


Tags: importltdefdownblackspeedupturtle
1条回答
网友
1楼 · 发布于 2024-04-20 03:18:03

any good way to do it without guessing correct coordinates and after return to the point where was ear started

此代码应执行您请求的两个操作: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

相关问题 更多 >