Python用turtle写张洋洋
时间: 2024-04-07 18:26:52 浏览: 98
使用Python的turtle模块可以绘制各种图形,包括张洋洋。下面是一个使用turtle模块绘制张洋洋的示例代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("white")
# 设置画笔颜色和粗细
turtle.pensize(3)
turtle.pencolor("black")
# 绘制张洋洋的头部
turtle.circle(100)
# 绘制张洋洋的眼睛
turtle.penup()
turtle.goto(-40, 120)
turtle.pendown()
turtle.circle(10)
turtle.penup()
turtle.goto(40, 120)
turtle.pendown()
turtle.circle(10)
# 绘制张洋洋的嘴巴
turtle.penup()
turtle.goto(-40, 80)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(40, 120)
# 绘制张洋洋的身体
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.setheading(-30)
turtle.forward(200)
turtle.setheading(60)
turtle.forward(200)
turtle.setheading(150)
turtle.forward(200)
turtle.setheading(240)
turtle.forward(200)
# 绘制张洋洋的手臂
turtle.penup()
turtle.goto(-100, -100)
turtle.pendown()
turtle.setheading(-30)
turtle.forward(100)
turtle.setheading(-120)
turtle.forward(100)
# 绘制张洋洋的腿
turtle.penup()
turtle.goto(100, -100)
turtle.pendown()
turtle.setheading(30)
turtle.forward(100)
turtle.setheading(120)
turtle.forward(100)
# 隐藏画笔
turtle.hideturtle()
# 结束绘制
turtle.done()
```
阅读全文