python画企鹅代码
时间: 2023-11-13 18:54:52 浏览: 273
以下是Python画企鹅的代码:
```python
import turtle
# 画圆函数
def draw_circle(x, y, r, color):
turtle.penup()
turtle.goto(x, y-r)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
# 画矩形函数
def draw_rect(x, y, w, h, color):
turtle.penup()
turtle.goto(x-w/2, y-h/2)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(2):
turtle.forward(w)
turtle.left(90)
turtle.forward(h)
turtle.left(90)
turtle.end_fill()
# 画企鹅函数
def draw_penguin(x, y):
# 画身体
draw_circle(x, y, 80, "black")
# 画腹部
draw_circle(x, y-70, 60, "white")
# 画左眼
draw_circle(x-25, y+60, 20, "white")
draw_circle(x-25, y+60, 10, "black")
# 画右眼
draw_circle(x+25, y+60, 20, "white")
draw_circle(x+25, y+60, 10, "black")
# 画嘴巴
draw_rect(x, y+20,40, 10, "orange")
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("lightblue")
# 画企鹅
draw_penguin(0, 0)
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
阅读全文