用python,turtle写单词Dream
时间: 2024-05-01 07:22:48 浏览: 95
以下是用 Python 的 Turtle 模块绘制单词 "Dream" 的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(500, 500)
turtle.bgcolor("black")
# 定义绘制字母的函数
def draw_d():
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.pensize(10)
turtle.color("white")
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.circle(-50, 180, 30)
turtle.right(180)
turtle.circle(-50, -180, 30)
turtle.right(180)
turtle.forward(100)
def draw_r():
turtle.penup()
turtle.goto(-50, 0)
turtle.pendown()
turtle.pensize(10)
turtle.color("white")
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.circle(-50, 180, 30)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.circle(-25, 180)
turtle.left(90)
turtle.forward(50)
def draw_e():
turtle.penup()
turtle.goto(50, 0)
turtle.pendown()
turtle.pensize(10)
turtle.color("white")
turtle.right(90)
turtle.forward(100)
turtle.right(180)
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(180)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
def draw_a():
turtle.penup()
turtle.goto(150, 0)
turtle.pendown()
turtle.pensize(10)
turtle.color("white")
turtle.right(180)
turtle.circle(50, -180, 30)
turtle.right(180)
turtle.circle(25, -180, 30)
turtle.right(180)
turtle.forward(50)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
def draw_m():
turtle.penup()
turtle.goto(250, 0)
turtle.pendown()
turtle.pensize(10)
turtle.color("white")
turtle.right(90)
turtle.forward(100)
turtle.left(150)
turtle.forward(75)
turtle.right(120)
turtle.forward(75)
turtle.left(150)
turtle.forward(100)
# 调用函数绘制单词
draw_d()
draw_r()
draw_e()
draw_a()
draw_m()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,可在窗口中看到绘制出的单词 "Dream"。
阅读全文