python画图小黄人
时间: 2023-07-24 21:04:41 浏览: 180
用python画小黄人源码
以下是用Python Turtle库画出的小黄人示例代码:
```python
import turtle
# 设置小黄人的头部
def draw_head():
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("yellow")
turtle.circle(100)
turtle.end_fill()
# 画眼睛
def draw_eyes():
turtle.penup()
turtle.goto(-60, 160)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-60, 160)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 160)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(60, 160)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.circle(10)
turtle.end_fill()
# 画嘴巴
def draw_mouth():
turtle.penup()
turtle.goto(-60, 80)
turtle.pendown()
turtle.pensize(8)
turtle.right(60)
turtle.circle(80, -120)
turtle.left(60)
# 画身体
def draw_body():
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color("blue")
turtle.circle(150, -180)
turtle.forward(300)
turtle.circle(150, -180)
turtle.forward(300)
turtle.end_fill()
# 画手
def draw_hands():
turtle.penup()
turtle.goto(-200, 60)
turtle.pendown()
turtle.begin_fill()
turtle.color("blue")
turtle.right(60)
turtle.circle(100, -60)
turtle.left(120)
turtle.circle(100, -60)
turtle.end_fill()
turtle.penup()
turtle.goto(200, 60)
turtle.pendown()
turtle.begin_fill()
turtle.color("blue")
turtle.right(120)
turtle.circle(-100, -60)
turtle.left(120)
turtle.circle(-100, -60)
turtle.end_fill()
# 画脚
def draw_feet():
turtle.penup()
turtle.goto(-70, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.right(60)
turtle.circle(80, -60)
turtle.left(120)
turtle.circle(80, -60)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color("black")
turtle.right(120)
turtle.circle(-80, -60)
turtle.left(120)
turtle.circle(-80, -60)
turtle.end_fill()
# 主函数
def main():
turtle.speed(10) # 设置画笔速度
draw_head()
draw_eyes()
draw_mouth()
draw_body()
draw_hands()
draw_feet()
turtle.done() # 绘画完成
if __name__ == '__main__':
main()
```
运行以上代码,即可得到小黄人的图像。
阅读全文