写个用python画哆啦A梦的代码
时间: 2023-05-22 21:06:02 浏览: 112
好的,下面是用Python画哆啦A梦的代码:
```
# -*- coding:utf-8 -*-
import turtle
# 定义一个函数,用于画出哆啦A梦的头部
def draw_head():
turtle.color('blue','lightblue')
turtle.penup()
turtle.goto(0, 120)
turtle.pendown()
turtle.setheading(-45)
turtle.begin_fill()
for i in range(2):
turtle.forward(150)
turtle.circle(-50, 90)
turtle.forward(150)
turtle.circle(-50, 90)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 20)
turtle.pendown()
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 20)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.color('white')
turtle.penup()
turtle.goto(-20, 38)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 38)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.color('black')
turtle.penup()
turtle.goto(-20, 50)
turtle.pendown()
turtle.dot(5)
turtle.penup()
turtle.goto(20, 50)
turtle.pendown()
turtle.dot(5)
# 定义一个函数,用于画出哆啦A梦的身体
def draw_body():
turtle.color('blue','lightblue')
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(-180)
turtle.begin_fill()
turtle.circle(70, -180)
turtle.circle(200, -60)
turtle.circle(70, -180)
turtle.end_fill()
turtle.penup()
turtle.goto(-140, -120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(140, -120)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.color('white')
turtle.penup()
turtle.goto(-95, -60)
turtle.pendown()
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
turtle.penup()
turtle.goto(95, -60)
turtle.pendown()
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
turtle.color('black')
turtle.penup()
turtle.goto(-95, -60)
turtle.pendown()
turtle.dot(5)
turtle.penup()
turtle.goto(95, -60)
turtle.pendown()
turtle.dot(5)
# 定义一个函数,用于画出哆啦A梦的胳膊
def draw_arm():
turtle.color('blue','lightblue')
turtle.penup()
turtle.goto(-210, -70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30, 150)
turtle.forward(40)
turtle.circle(10, 180)
turtle.forward(40)
turtle.circle(30, 150)
turtle.forward(60)
turtle.end_fill()
turtle.penup()
turtle.goto(210, -70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(-30, -150)
turtle.forward(40)
turtle.circle(-10, -180)
turtle.forward(40)
turtle.circle(-30, -150)
turtle.forward(60)
turtle.end_fill()
# 定义一个函数,用于画出哆啦A梦的腿
def draw_leg():
turtle.color('blue','lightblue')
turtle.penup()
turtle.goto(-80, -300)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(80, -300)
turtle.pendown()
turtle.begin_fill()
turtle.circle(-30)
turtle.end_fill()
# 设置画布和画笔属性
turtle.setup(800, 600)
turtle.hideturtle()
turtle.speed(10)
turtle.tracer(False)
# 画出哆啦A梦的头部
draw_head()
# 画出哆啦A梦的身体
draw_body()
# 画出哆啦A梦的胳膊
draw_arm()
# 画出哆啦A梦的腿
draw_leg()
turtle.done()
```
希望能够帮到你!
阅读全文