python画冰墩墩代码
时间: 2023-07-09 15:46:04 浏览: 149
以下是使用Python和turtle库画出冰墩墩的代码:
```python
import turtle
# 绘制圆形
def draw_circle(x, y, size, color):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(size)
turtle.end_fill()
# 绘制眼睛
def draw_eyes(x, y, size):
draw_circle(x - size, y, size / 2, 'white')
draw_circle(x - size / 2, y, size / 4, 'black')
# 绘制鼻子
def draw_nose(x, y, size):
draw_circle(x, y, size / 2, 'black')
# 绘制嘴巴
def draw_mouth(x, y, size):
turtle.penup()
turtle.goto(x - size / 2, y - size / 2)
turtle.pendown()
turtle.goto(x + size / 2, y - size / 2)
turtle.right(90)
turtle.circle(size / 2, 180)
# 绘制冰墩墩
def draw_penguin(x, y, size):
draw_circle(x, y, size, 'black')
draw_circle(x, y + size / 2, size / 2, 'white')
draw_eyes(x, y + size / 4, size / 10)
draw_nose(x, y, size / 10)
draw_mouth(x, y - size / 4, size / 2)
# 设置画布大小
turtle.setup(800, 600)
# 绘制多个冰墩墩
draw_penguin(-200, 0, 100)
draw_penguin(0, 0, 150)
draw_penguin(200, 0, 200)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.mainloop()
```
你可以通过修改draw_penguin函数的参数来改变冰墩墩的位置和大小。
阅读全文