python turtle画佩奇与乔治踩泥坑
时间: 2023-09-13 11:04:53 浏览: 134
画一个乔治或者佩奇
好的,请稍等片刻,我来为您展示一下Python turtle画佩奇与乔治踩泥坑的代码:
```python
import turtle
# 画佩奇
peppa = turtle.Turtle()
peppa.penup()
peppa.goto(-75, 0)
peppa.pendown()
peppa.pensize(5)
peppa.color('#f68d99')
peppa.speed(10)
peppa.circle(70)
peppa.penup()
peppa.goto(-40, 60)
peppa.pendown()
peppa.color('#ffffff')
peppa.begin_fill()
peppa.circle(15)
peppa.end_fill()
peppa.penup()
peppa.goto(10, 60)
peppa.pendown()
peppa.color('#ffffff')
peppa.begin_fill()
peppa.circle(15)
peppa.end_fill()
peppa.penup()
peppa.goto(-4, 45)
peppa.pendown()
peppa.color('#000000')
peppa.begin_fill()
peppa.circle(5)
peppa.end_fill()
peppa.penup()
peppa.goto(54, 60)
peppa.pendown()
peppa.color('#ffffff')
peppa.begin_fill()
peppa.circle(15)
peppa.end_fill()
peppa.penup()
peppa.goto(60, 45)
peppa.pendown()
peppa.color('#000000')
peppa.begin_fill()
peppa.circle(5)
peppa.end_fill()
# 添加佩奇的手臂
peppa.penup()
peppa.goto(-75, 20)
peppa.pendown()
peppa.pensize(12)
peppa.right(45)
peppa.forward(50)
peppa.penup()
peppa.goto(-75, -5)
peppa.pendown()
peppa.right(45)
peppa.forward(50)
# 添加佩奇的鼻子
peppa.penup()
peppa.goto(-20, 10)
peppa.pendown()
peppa.pencolor('#f68d99')
peppa.fillcolor('#f68d99')
peppa.begin_fill()
peppa.left(45)
peppa.forward(20)
peppa.right(135)
peppa.forward(20)
peppa.right(135)
peppa.forward(20)
peppa.end_fill()
# 画乔治
george = turtle.Turtle()
george.penup()
george.goto(75, 0)
george.pendown()
george.pensize(5)
george.color('#ffe4b5')
george.speed(10)
george.circle(70)
george.penup()
george.goto(40, 60)
george.pendown()
george.color('#ffffff')
george.begin_fill()
george.circle(15)
george.end_fill()
george.penup()
george.goto(-10, 60)
george.pendown()
george.color('#ffffff')
george.begin_fill()
george.circle(15)
george.end_fill()
george.penup()
george.goto(6, 45)
george.pendown()
george.color('#000000')
george.begin_fill()
george.circle(5)
george.end_fill()
george.penup()
george.goto(-44, 60)
george.pendown()
george.color('#ffffff')
george.begin_fill()
george.circle(15)
george.end_fill()
george.penup()
george.goto(-50, 45)
george.pendown()
george.color('#000000')
george.begin_fill()
george.circle(5)
george.end_fill()
# 添加乔治的手臂
george.penup()
george.goto(75, 20)
george.pendown()
george.pensize(12)
george.left(45)
george.forward(50)
george.penup()
george.goto(75, -5)
george.pendown()
george.left(45)
george.forward(50)
# 添加乔治的尾巴
george.penup()
george.goto(-30, -40)
george.pendown()
george.pencolor('#ffe4b5')
george.fillcolor('#ffe4b5')
george.begin_fill()
george.right(45)
george.forward(40)
george.right(90)
george.forward(20)
george.right(90)
george.forward(10)
george.right(90)
george.forward(20)
george.right(45)
george.forward(20)
george.end_fill()
# 踩泥坑
stamp_size = 20
turtle.penup()
turtle.color("brown")
turtle.goto(-150, -150)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.penup()
turtle.color("green")
turtle.goto(-150, -130)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.penup()
turtle.color("brown")
turtle.goto(-150, -110)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.penup()
turtle.color("green")
turtle.goto(-150, -90)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.penup()
turtle.color("brown")
turtle.goto(-150, -70)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.penup()
turtle.color("green")
turtle.goto(-150, -50)
for i in range(20):
turtle.stamp()
turtle.forward(stamp_size)
turtle.done()
```
可以通过运行以上代码在画布上绘制出佩奇和乔治,以及他们在泥坑中踩踏的痕迹。希望这可以回答您的问题。
阅读全文