python画小熊猫代码
时间: 2023-11-08 08:01:07 浏览: 200
import turtle
# 设置绘制窗口的大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("white")
# 定义画笔颜色函数
def set_color(color1, color2):
turtle.pencolor(color1)
turtle.fillcolor(color2)
# 绘制熊猫的头部
def draw_head():
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.setheading(45)
set_color("black", "white")
turtle.begin_fill()
turtle.circle(200, steps=4)
turtle.end_fill()
# 绘制熊猫的耳朵
def draw_ears():
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(45)
set_color("black", "black")
turtle.begin_fill()
turtle.circle(60, steps=4)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(135)
turtle.begin_fill()
turtle.circle(60, steps=4)
turtle.end_fill()
# 绘制熊猫的眼睛
def draw_eyes():
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
set_color("black", "black")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
set_color("black", "black")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 绘制熊猫的鼻子
def draw_nose():
turtle.penup()
turtle.goto(0, -20)
turtle.pendown()
set_color("black", "black")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制熊猫的嘴巴
def draw_mouth():
turtle.penup()
turtle.goto(-50, -60)
turtle.pendown()
set_color("black", "black")
turtle.right(90)
turtle.circle(50, 180)
# 绘制熊猫的身体
def draw_body():
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
set_color("black", "white")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 绘制熊猫的手
def draw_hands():
turtle.penup()
turtle.goto(100, -250)
turtle.pendown()
set_color("black", "white")
turtle.setheading(-30)
turtle.begin_fill()
turtle.circle(80, 120)
turtle.left(60)
turtle.circle(80, 120)
turtle.end_fill()
# 绘制熊猫的脚
def draw_feet():
turtle.penup()
turtle.goto(-100, -250)
turtle.pendown()
set_color("black", "white")
turtle.setheading(-150)
turtle.begin_fill()
turtle.circle(80, 120)
turtle.left(60)
turtle.circle(80, 120)
turtle.end_fill()
# 调用各个函数绘制熊猫
draw_head()
draw_ears()
draw_eyes()
draw_nose()
draw_mouth()
draw_body()
draw_hands()
draw_feet()
# 隐藏画笔
turtle.hideturtle()
#
阅读全文