python - 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()
这一定很丑,但我才刚刚开始学习如何编码。
我不知道是否有一种有效的方法来使用乌龟使用数学或其他方式来绘制图片,但我随机地做了一点。
解决方案
@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()
推荐阅读
- python - 在尝试量化张量流模型时,“EndVector() 需要 1 个位置参数,但给出了 2 个”
- html - 在单行而不是多行上显示文本
- powershell - wmic 与 powershell 顺序的子命令。(“wmic”然后是下一行“csproduct”)。子命令“csproduct”未执行
- azure - 具有多个站点的应用程序网关的 Azure 流量管理器自定义标头设置
- mysql - MySQL中多次执行sql查询,类似于TSQL(SQL Server)中的GO
- sql - impala shell 输出带有附件的 csv 文件生成
- django - 在 django + vue 应用程序中使用 axios 时出错
- java - Gradle Kotlin DSL:找不到或加载主类
- android - Android Room - 每个应用程序一个或多个实例?
- sql - 组匹配值并查找哪些缺少相关值?