用python画一只可爱的小猪的图形,然后在猪的脸上写“周逸娇是小胖子”
时间: 2024-03-12 18:50:22 浏览: 118
py代码-绘制小猪佩奇
以下是一个使用Python的turtle模块绘制小猪并在脸上写字的示例代码:
```python
import turtle
# 绘制小猪的函数
def draw_pig():
# 设置画笔颜色和粗细
turtle.pensize(3)
turtle.pencolor('pink')
turtle.fillcolor('pink')
# 绘制头部
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 绘制耳朵
turtle.penup()
turtle.goto(-30, 80)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 80)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 绘制眼睛
turtle.penup()
turtle.goto(-20, 20)
turtle.pendown()
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
turtle.penup()
turtle.goto(20, 20)
turtle.pendown()
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 绘制鼻子
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 绘制嘴巴
turtle.penup()
turtle.goto(0, -20)
turtle.pendown()
turtle.pencolor('red')
turtle.right(90)
turtle.circle(20, 180)
# 在猪的脸上写字
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.pencolor('black')
turtle.write('周逸娇是小胖子', align='center', font=('Arial', 16, 'normal'))
# 初始化画布和画笔
turtle.setup(400, 400)
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
# 调用绘制小猪的函数
draw_pig()
# 点击关闭窗口
turtle.exitonclick()
```
运行以上代码后,会在窗口中绘制一只可爱的小猪,并在猪的脸上写上了“周逸娇是小胖子”这句话。你可以根据需要修改代码中的颜色、大小、字体等参数来调整小猪的样子和文本的样式。
阅读全文