python利用turtle绘制哆啦A梦
时间: 2023-09-28 22:12:26 浏览: 207
好的,下面是利用Python的turtle模块绘制哆啦A梦的代码:
```python
import turtle
# 设置turtle窗口的大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('white')
# 绘制哆啦A梦的头部
turtle.pensize(3)
turtle.color('blue', 'lightblue')
turtle.begin_fill()
turtle.circle(120)
turtle.end_fill()
# 绘制哆啦A梦的耳朵
turtle.penup()
turtle.goto(-80, 80)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(80, 80)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
# 绘制哆啦A梦的眼睛
turtle.penup()
turtle.goto(-50, 20)
turtle.pendown()
turtle.color('black', 'white')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 20)
turtle.pendown()
turtle.color('black', 'white')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-50, 30)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 30)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制哆啦A梦的鼻子
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.color('black', 'pink')
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
# 绘制哆啦A梦的嘴巴
turtle.penup()
turtle.goto(-50, -40)
turtle.pendown()
turtle.color('red', 'red')
turtle.begin_fill()
turtle.circle(30, 180)
turtle.end_fill()
# 绘制哆啦A梦的身体
turtle.penup()
turtle.goto(-170, -120)
turtle.pendown()
turtle.color('blue', 'lightblue')
turtle.begin_fill()
turtle.forward(340)
turtle.circle(100, 180)
turtle.forward(340)
turtle.end_fill()
# 绘制哆啦A梦的手和脚
turtle.penup()
turtle.goto(-130, -160)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(130, -160)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(-150, -270)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -270)
turtle.pendown()
turtle.color('blue', 'white')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制哆啦A梦的口袋
turtle.penup()
turtle.goto(-80, -120)
turtle.pendown()
turtle.color('black', 'white')
turtle.begin_fill()
turtle.circle(60)
turtle.end_fill()
# 绘制哆啦A梦的口袋口
turtle.penup()
turtle.goto(-60, -130)
turtle.pendown()
turtle.color('red', 'red')
turtle.begin_fill()
turtle.circle(25, 180)
turtle.end_fill()
# 绘制哆啦A梦的铃铛
turtle.penup()
turtle.goto(-60, -200)
turtle.pendown()
turtle.color('yellow', 'yellow')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-80, -240)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, -240)
turtle.pendown()
turtle.color('black', 'black')
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 隐藏turtle画笔
turtle.hideturtle()
# 点击关闭turtle窗口
turtle.done()
```
运行上述代码,即可在turtle窗口中看到绘制的哆啦A梦。
阅读全文