python绘制哆啦a梦
时间: 2023-10-14 16:24:31 浏览: 115
要在Python中绘制哆啦A梦,可以使用Python的turtle库。下面是一个简单的例子:
```python
import turtle
# 设置画笔
t = turtle.Pen()
t.speed(0)
t.pensize(3)
# 绘制哆啦A梦的头部
t.color('blue', 'blue')
t.begin_fill()
t.circle(100)
t.end_fill()
# 绘制哆啦A梦的耳朵
t.penup()
t.goto(50, 180)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.goto(-50, 180)
t.pendown()
t.begin_fill()
t.circle(30)
t.end_fill()
# 绘制哆啦A梦的眼睛
t.penup()
t.goto(-30, 50)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(30, 50)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(-20, 60)
t.pendown()
t.color('black', 'black')
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.goto(40, 60)
t.pendown()
t.color('black', 'black')
t.begin_fill()
t.circle(10)
t.end_fill()
# 绘制哆啦A梦的鼻子
t.penup()
t.goto(0, 20)
t.pendown()
t.color('pink', 'pink')
t.begin_fill()
t.circle(10)
t.end_fill()
# 绘制哆啦A梦的嘴巴
t.penup()
t.goto(-50, -20)
t.pendown()
t.color('black', 'black')
t.goto(50, -20)
t.goto(50, -40)
t.goto(-50, -40)
t.goto(-50, -20)
# 绘制哆啦A梦的身体
t.penup()
t.goto(-100, -100)
t.pendown()
t.color('blue', 'blue')
t.begin_fill()
for i in range(2):
t.forward(200)
t.circle(50, 180)
t.end_fill()
# 绘制哆啦A梦的手和脚
t.penup()
t.goto(-100, -150)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(100, -150)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(-100, -200)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
t.penup()
t.goto(100, -200)
t.pendown()
t.color('white', 'white')
t.begin_fill()
t.circle(20)
t.end_fill()
# 隐藏画笔
t.hideturtle()
# 等待窗口关闭
turtle.done()
```
运行上述代码,将会绘制出一个哆啦A梦的图像。
阅读全文
相关推荐















