python turtle库画猪猪侠
时间: 2023-06-20 09:03:10 浏览: 271
好的,以下是Python Turtle库画猪猪侠的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#fff")
# 画猪猪侠的头
turtle.penup()
turtle.goto(-70, 150)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画猪猪侠的眼睛
turtle.penup()
turtle.goto(-40, 210)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 210)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 画猪猪侠的鼻子
turtle.penup()
turtle.goto(0, 160)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画猪猪侠的嘴巴
turtle.penup()
turtle.goto(-40, 120)
turtle.pendown()
turtle.right(45)
turtle.circle(60, 90)
# 画猪猪侠的脸
turtle.penup()
turtle.goto(-170, -50)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 画猪猪侠的耳朵
turtle.penup()
turtle.goto(-140, 170)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.right(45)
turtle.circle(80, -90)
turtle.circle(40, -90)
turtle.end_fill()
turtle.penup()
turtle.goto(140, 170)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.right(180)
turtle.circle(80, -90)
turtle.circle(40, -90)
turtle.end_fill()
# 画猪猪侠的身体
turtle.penup()
turtle.goto(-170, -50)
turtle.pendown()
turtle.fillcolor("#f00")
turtle.begin_fill()
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.circle(200, -180)
turtle.right(90)
turtle.forward(50)
turtle.end_fill()
# 画猪猪侠的腿
turtle.penup()
turtle.goto(-150, -200)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -200)
turtle.pendown()
turtle.fillcolor("#000")
turtle.begin_fill()
turtle.right(180)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
# 画猪猪侠的手
turtle.penup()
turtle.goto(-250, 0)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(250, 0)
turtle.pendown()
turtle.fillcolor("#fdd")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行上述代码,即可在画布上看到猪猪侠的图案。
阅读全文