编写python代码用turtle库画字母WLXY
时间: 2024-05-08 17:07:44 浏览: 81
用Python的turtle库画柯南_python画柯南_python_Turtle_画图_柯南python制作_源码
5星 · 资源好评率100%
import turtle
# 创建一个画布
canvas = turtle.Screen()
# 创建一个海龟对象
pen = turtle.Turtle()
# 设置画笔宽度和颜色
pen.pensize(5)
pen.color("red")
# 画字母W
pen.left(60)
pen.forward(100)
pen.right(120)
pen.forward(100)
pen.left(120)
pen.forward(100)
pen.right(120)
pen.forward(100)
# 画字母L
pen.up()
pen.goto(150,0)
pen.down()
pen.left(90)
pen.forward(100)
pen.right(90)
pen.forward(50)
# 画字母X
pen.up()
pen.goto(225,0)
pen.down()
pen.left(45)
pen.forward(70)
pen.up()
pen.goto(225,0)
pen.down()
pen.right(45)
pen.forward(70)
# 画字母Y
pen.up()
pen.goto(300,0)
pen.down()
pen.left(90)
pen.forward(50)
pen.left(45)
pen.forward(50)
pen.up()
pen.goto(300,0)
pen.down()
pen.right(45)
pen.forward(50)
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
阅读全文