python代码:画图哆啦a梦
时间: 2023-11-12 22:05:54 浏览: 91
python画哆啦A梦
5星 · 资源好评率100%
下面是用Python代码画出哆啦A梦的例子:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("#ffffcc")
pen = turtle.Turtle()
pen.shape("turtle")
pen.speed(0)
pen.pensize(3)
# 画哆啦A梦的头
pen.color("#ffcc33")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画哆啦A梦的耳朵
pen.color("#ffcc33")
pen.begin_fill()
pen.goto(-50, 180)
pen.circle(30)
pen.end_fill()
pen.color("#ffcc33")
pen.begin_fill()
pen.goto(50, 180)
pen.circle(30)
pen.end_fill()
# 画哆啦A梦的眼睛
pen.penup()
pen.goto(-40, 80)
pen.pendown()
pen.color("#ffffff")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(40, 80)
pen.pendown()
pen.color("#ffffff")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(-40, 80)
pen.pendown()
pen.color("#000000")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(40, 80)
pen.pendown()
pen.color("#000000")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画哆啦A梦的鼻子
pen.penup()
pen.goto(0, 40)
pen.pendown()
pen.color("#ff3300")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 画哆啦A梦的嘴巴
pen.penup()
pen.goto(-60, -20)
pen.pendown()
pen.color("#ff99cc")
pen.right(60)
pen.circle(80, 120)
# 画哆啦A梦的身体
pen.penup()
pen.goto(-120, -100)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.forward(240)
pen.left(90)
pen.circle(50, 180)
pen.left(90)
pen.forward(240)
pen.end_fill()
# 画哆啦A梦的胳膊
pen.penup()
pen.goto(-120, -100)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.right(45)
pen.forward(100)
pen.right(90)
pen.forward(100)
pen.right(45)
pen.end_fill()
pen.penup()
pen.goto(120, -100)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.left(90)
pen.forward(100)
pen.left(45)
pen.end_fill()
# 画哆啦A梦的手和脚
pen.penup()
pen.goto(-120, -240)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.right(45)
pen.forward(80)
pen.right(90)
pen.forward(80)
pen.right(45)
pen.end_fill()
pen.penup()
pen.goto(120, -240)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.left(45)
pen.forward(80)
pen.left(90)
pen.forward(80)
pen.left(45)
pen.end_fill()
pen.penup()
pen.goto(-60, -300)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.circle(40)
pen.end_fill()
pen.penup()
pen.goto(60, -300)
pen.pendown()
pen.color("#ffcc33")
pen.begin_fill()
pen.circle(40)
pen.end_fill()
# 完成画图
pen.hideturtle()
canvas.exitonclick()
```
运行代码后,将会弹出一个窗口,显示出哆啦A梦的图像。
阅读全文