用turtle写自己的名字
时间: 2023-06-19 10:03:36 浏览: 253
python——用Turtle画画写名字(csdn)————程序.pdf
5星 · 资源好评率100%
下面是使用Python的Turtle模块写出我的名字的代码:
```python
import turtle
# 设置画笔大小和颜色
turtle.pensize(5)
turtle.pencolor("purple")
# 绘制字母“J”
turtle.left(90)
turtle.forward(100)
turtle.right(180)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
# 移动到字母“O”的起点
turtle.up()
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(180)
# 绘制字母“O”
turtle.down()
turtle.circle(25)
# 移动到字母“E”的起点
turtle.up()
turtle.right(90)
turtle.forward(75)
turtle.right(90)
turtle.forward(50)
turtle.right(180)
# 绘制字母“E”
turtle.down()
turtle.forward(50)
turtle.up()
turtle.right(90)
turtle.forward(25)
turtle.right(180)
turtle.down()
turtle.forward(25)
turtle.up()
turtle.right(180)
turtle.forward(25)
turtle.right(90)
turtle.down()
turtle.forward(50)
# 隐藏画笔
turtle.hideturtle()
# 点击窗口关闭
turtle.exitonclick()
```
这个代码将会绘制出我的名字 "Jason",效果如下图所示:
![Jason](https://i.imgur.com/44Gr5dM.png)
阅读全文