用python写一个猫猫形状的平面图形
时间: 2023-08-04 20:35:07 浏览: 153
python画kitty
好的,以下是一个简单的 Python 代码,用于绘制一个猫猫形状的平面图形:
```python
import turtle
# 设置画布和画笔
screen = turtle.Screen()
screen.bgcolor("white")
pen = turtle.Turtle()
pen.speed(0)
pen.color("black")
pen.pensize(3)
# 绘制头部
pen.fillcolor("#ffc0cb")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 绘制耳朵
pen.fillcolor("#ffc0cb")
pen.begin_fill()
pen.setheading(50)
pen.circle(40, 100)
pen.setheading(0)
pen.forward(30)
pen.setheading(130)
pen.circle(-40, 100)
pen.setheading(180)
pen.forward(30)
pen.end_fill()
# 绘制眼睛
pen.penup()
pen.goto(-40, 120)
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.pendown()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(40, 120)
pen.pendown()
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(60, 120)
pen.fillcolor("black")
pen.begin_fill()
pen.circle(10)
pen.end_fill()
# 绘制鼻子
pen.penup()
pen.goto(0, 80)
pen.pendown()
pen.fillcolor("black")
pen.begin_fill()
pen.circle(15)
pen.end_fill()
# 绘制嘴巴
pen.penup()
pen.goto(-40, 50)
pen.pendown()
pen.setheading(-20)
pen.circle(30, 120)
pen.penup()
pen.goto(-40, 50)
pen.pendown()
pen.setheading(-160)
pen.circle(30, -120)
# 绘制身体
pen.penup()
pen.goto(-80, -50)
pen.fillcolor("#ffc0cb")
pen.begin_fill()
pen.setheading(0)
pen.forward(150)
pen.setheading(270)
pen.forward(200)
pen.setheading(180)
pen.forward(150)
pen.setheading(90)
pen.forward(200)
pen.end_fill()
# 绘制腿和爪子
pen.penup()
pen.goto(-60, -150)
pen.fillcolor("#ffc0cb")
pen.begin_fill()
pen.setheading(0)
pen.forward(40)
pen.setheading(-90)
pen.forward(50)
pen.setheading(270)
pen.circle(-20, 180)
pen.setheading(90)
pen.forward(50)
pen.end_fill()
pen.penup()
pen.goto(20, -150)
pen.fillcolor("#ffc0cb")
pen.begin_fill()
pen.setheading(0)
pen.forward(40)
pen.setheading(-90)
pen.forward(50)
pen.setheading(270)
pen.circle(-20, 180)
pen.setheading(90)
pen.forward(50)
pen.end_fill()
pen.penup()
pen.goto(-60, -100)
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(20, -100)
pen.fillcolor("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(-75, -130)
pen.fillcolor("black")
pen.begin_fill()
pen.circle(5)
pen.end_fill()
pen.penup()
pen.goto(-55, -130)
pen.fillcolor("black")
pen.begin_fill()
pen.circle(5)
pen.end_fill()
pen.penup()
pen.goto(5, -130)
pen.fillcolor("black")
pen.begin_fill()
pen.circle(5)
pen.end_fill()
pen.penup()
pen.goto(25, -130)
pen.fillcolor("black")
pen.begin_fill()
pen.circle(5)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
turtle.done()
```
运行以上代码,即可绘制出一个猫猫形状的平面图形。
阅读全文