首页 > 解决方案 > Python海龟颜色没有正确填充

问题描述

我是编程初学者,我正在尝试从吉卜力电影中画龙猫,但身体无法正常填充。

这是我正在尝试用这种颜色绘制的图,但这就是我得到的。这是我的代码:

from turtle import *
"""corps"""
import turtle

def corps():

    speed("fast")
    color('black'),width(2)
    begin_fill()
    up()
    #right side down
    goto(0,-200)
    down()
    right(90)
    forward(4)
    circle(5,90)
    forward(70)
    circle(130,90)
    forward(140)
    circle(50,20)
    up()
    #left side down
    right(-160)
    goto(0,-200)
    down()
    forward(4)
    circle(-5,90)
    forward(70)
    circle(-130,90)
    forward(140)
    circle(-50,20)
    up()
    #right side up
    right(70)
    goto(205,-79)
    down()
    forward(5)
    circle(20,70)
    circle(100,10)
    circle(500,10)
    circle(200,30)
    circle(3800,3)
    right(33)
    forward(30)
    circle(100,23)
    circle(5,115)
    circle(200,15)
    right(63)
    forward(70)
    up()
    #left side up
    goto(-205,-79)
    down()
    forward(5)
    circle(-20,70)
    circle(-100,10)
    circle(-500,10)
    circle(-200,30)
    circle(-3800,3)
    right(-33)
    forward(30)
    circle(-100,23)
    circle(-5,115)
    circle(-200,15)
    right(-63)
    forward(65)
    turtle.fillcolor('#66615D')
    end_fill()
    up()
    #belly
    begin_fill()
    turtle.fillcolor('#A99E82')
    goto(0,-200)
    down()
    circle(200)
    end_fill()

corps()
done()

这一定很丑,但我才刚刚开始学习如何编码。

我不知道是否有一种有效的方法来使用乌龟使用数学或其他方式来绘制图片,但我随机地做了一点。

标签: pythonturtle-graphics

解决方案


@RogerAsbey 在这一点上是正确的(+1):

如果你能在一条连续的线上画出轮廓,它就会均匀地填充。

所以让我们重新编写代码来做到这一点。您仍然可以谨慎地考虑它,但只需确保一个流到下一个而不是跳来跳去:

from turtle import *

speed("fastest")
width(2)

color('#36302A', '#545049')

begin_fill()

up()
goto(0, -200)
right(90)
down()

# right side lower
forward(4)
circle(5, 90)
forward(70)
circle(130, 90)
forward(140)
circle(50, 20)
circle(50, -20)
backward(140)
right(90)

# right side upper
forward(5)
circle(20, 70)
circle(100, 10)
circle(500, 10)
circle(200, 30)
circle(3800, 3)
right(33)
forward(30)
circle(100, 23)
circle(5, 115)
circle(200, 15)
right(63)

forward(130)

# left side upper
right(63)
circle(200, 15)
circle(5, 115)
circle(100, 23)
forward(30)
right(33)
circle(3800, 3)
circle(200, 30)
circle(500, 10)
circle(100, 10)
circle(20, 70)
forward(5)

# left side lower
right(90)
backward(140)
circle(50, -20)
circle(50, 20)
forward(140)
circle(130, 90)
forward(70)
circle(5, 90)
forward(4)

goto(0, -200)
right(90)

end_fill()

# belly
fillcolor('#A99881')

begin_fill()
circle(200)
end_fill()

hideturtle()

done()

在此处输入图像描述


推荐阅读