用户:小磨叽11111111111查看:0 回复:0 评论:0 创建时间:2019-10-31T17:24:12
【作品展示】

【作品介绍】
turtle画图基础重点使用setheading()设置角度方向,circle()绘制圆弧,详情见代码。
【作品源代码】
import turtle
t = turtle.Pen()
t.speed(0)
turtle.colormode(255) # 设置颜色模式为RGB
turtle.bgcolor(0, 0, 0) # 设置背景颜色为黑色
# 不留痕迹移动画笔
def move(x, y):
t.setheading(0)
t.penup()
t.goto(x, y)
t.pendown()
# 画椭圆
def ellipse(length=150):
t.pensize(5)
t.fillcolor(252, 125, 10)
t.begin_fill()
t.setheading(-90)
t.circle(30, 180)
t.setheading(90)
t.forward(length)
t.setheading(90)
t.circle(30, 180)
t.setheading(270)
t.forward(length)
t.end_fill()
# 南瓜
move(-150, -150)
for i in range(6):
ellipse()
t.setheading(0)
t.penup()
t.forward(50)
t.pendown()
# 瓜藤
move(0, 40)
t.pencolor(0, 175, 80)
t.setheading(90)
for i in range(50, 30, -1):
t.pensize(i)
t.forward(3)
t.right(3)
t.pencolor(0, 0, 0)
t.fillcolor(0, 0, 0)
# 左眼
move(-30, -50)
t.setheading(-135)
t.pensize(5)
t.begin_fill()
t.circle(-30, 180)
t.right(90)
t.forward(56)
t.end_fill()
# 右眼
move(30, -50)
t.setheading(-45)
t.pensize(5)
t.begin_fill()
t.circle(30, 180)
t.left(90)
t.forward(56)
t.end_fill()
# 鼻子
move(-10, -80)
t.setheading(0)
t.begin_fill()
for i in range(3):
t.forward(30)
t.left(120)
t.end_fill()
# 嘴巴
move(-60, -120)
t.pensize(10)
t.pencolor(255, 239, 141)
for i in range(8):
t.setheading(-45)
t.forward(10)
t.setheading(45)
t.forward(10)
# 写字
move(0,200)
t.pencolor(255,255,255)
t.write("trick or treat", align="center", font=("Courier New", 40, "normal"))
t.hideturtle()
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn