用turtle画史迪奇,生成代码
时间: 2024-05-13 11:15:41 浏览: 120
以下是使用 Python 的 turtle 模块绘制史迪奇的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#00A3E0")
# 绘制史迪奇的头部
turtle.pensize(4)
turtle.color("#FED202")
turtle.begin_fill()
turtle.circle(150)
turtle.end_fill()
# 绘制史迪奇的眼睛
turtle.penup()
turtle.goto(-60, 180)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 200)
turtle.pendown()
turtle.color("black")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 180)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 200)
turtle.pendown()
turtle.color("black")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制史迪奇的鼻子
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.color("#FF8F43")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制史迪奇的嘴巴
turtle.penup()
turtle.goto(-70, 20)
turtle.pendown()
turtle.color("#FF8F43")
turtle.pensize(10)
turtle.right(30)
turtle.circle(100, 60)
# 绘制史迪奇的耳朵
turtle.penup()
turtle.goto(-180, 150)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(45)
turtle.circle(80, -80)
turtle.circle(160, 40)
turtle.circle(40, 80)
turtle.circle(160, 40)
turtle.circle(80, -80)
turtle.end_fill()
turtle.penup()
turtle.goto(180, 150)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(180)
turtle.circle(80, -80)
turtle.circle(160, 40)
turtle.circle(40, 80)
turtle.circle(160, 40)
turtle.circle(80, -80)
turtle.end_fill()
# 绘制史迪奇的身体
turtle.penup()
turtle.goto(-150, -120)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(45)
turtle.forward(250)
turtle.right(90)
turtle.forward(350)
turtle.right(90)
turtle.forward(250)
turtle.right(90)
turtle.forward(350)
turtle.end_fill()
# 绘制史迪奇的手
turtle.penup()
turtle.goto(-250, -200)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(45)
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.end_fill()
turtle.penup()
turtle.goto(250, -200)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(180)
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.right(90)
turtle.forward(160)
turtle.right(90)
turtle.forward(80)
turtle.end_fill()
# 绘制史迪奇的脚
turtle.penup()
turtle.goto(-150, -350)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(45)
turtle.forward(120)
turtle.right(90)
turtle.forward(60)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.forward(60)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -350)
turtle.pendown()
turtle.color("#FED202")
turtle.begin_fill()
turtle.right(180)
turtle.forward(120)
turtle.right(90)
turtle.forward(60)
turtle.right(90)
turtle.forward(120)
turtle.right(90)
turtle.forward(60)
turtle.end_fill()
# 隐藏海龟箭头
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
运行代码,即可看到绘制的史迪奇图案。
阅读全文