写段代码,用python画个小猪佩奇
时间: 2023-09-17 13:05:56 浏览: 182
### 回答1:
代码:from PIL import Image, ImageDraw# Create an image
image = Image.new('RGB', (200, 200), 'white')# Create a draw object
draw = ImageDraw.Draw(image)# Draw a filled rectangle
draw.rectangle((20, 20, 180, 180), fill='pink')# Draw two black circles
draw.ellipse((50, 50, 150, 150), fill='black')
draw.ellipse((90, 90, 110, 110), fill='black')# Save the image
image.save('peppa.png')
### 回答2:
import turtle
# 设置画笔粗细和速度
turtle.pensize(5)
turtle.speed(3)
# 画头部
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.circle(100)
# 画耳朵
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.setheading(60)
turtle.circle(50, 120)
turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
turtle.setheading(120)
turtle.circle(-50, 120)
# 画眼睛
turtle.penup()
turtle.goto(-30, 80)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 80)
turtle.pendown()
turtle.fillcolor("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画鼻子
turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(20, 120)
# 画嘴巴
turtle.penup()
turtle.goto(-30, 0)
turtle.pendown()
turtle.setheading(-30)
turtle.circle(50, 60)
turtle.circle(50, 120)
turtle.setheading(0)
turtle.fd(30)
# 画脸颊
turtle.penup()
turtle.goto(-70, -10)
turtle.pendown()
turtle.setheading(150)
turtle.circle(90, 120)
turtle.penup()
turtle.goto(70, -10)
turtle.pendown()
turtle.setheading(30)
turtle.circle(-90, 120)
# 画身体
turtle.penup()
turtle.goto(-100, -200)
turtle.pendown()
turtle.fillcolor("pink")
turtle.begin_fill()
turtle.setheading(-60)
turtle.circle(120, 240)
turtle.setheading(90)
turtle.fd(200)
turtle.setheading(0)
turtle.fd(240)
turtle.setheading(-90)
turtle.fd(200)
turtle.circle(-120, 240)
turtle.penup()
turtle.end_fill()
# 画尾巴
turtle.penup()
turtle.goto(190, -40)
turtle.pendown()
turtle.fillcolor("pink")
turtle.begin_fill()
turtle.setheading(60)
turtle.circle(40, 120)
turtle.circle(40, 60)
turtle.setheading(-150)
turtle.fd(40)
turtle.setheading(150)
turtle.circle(-40, 120)
turtle.circle(-40, 60)
turtle.setheading(30)
turtle.fd(40)
turtle.penup()
turtle.end_fill()
# 画四肢
turtle.penup()
turtle.goto(-100, -200)
turtle.pendown()
turtle.fillcolor("pink")
turtle.begin_fill()
turtle.setheading(-30)
turtle.circle(150, 60)
turtle.circle(150, 120)
turtle.setheading(-90)
turtle.circle(150, 60)
turtle.penup()
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 结束
turtle.done()
### 回答3:
画个小猪佩奇的代码如下:
```python
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("white")
pen = turtle.Turtle()
# 画身体
pen.penup()
pen.goto(-100, -50)
pen.pendown()
pen.setheading(90)
pen.begin_fill()
pen.color("pink")
pen.circle(100)
pen.end_fill()
# 画脸
pen.penup()
pen.goto(-35, 50)
pen.pendown()
pen.setheading(90)
pen.begin_fill()
pen.color("light pink")
pen.circle(35)
pen.end_fill()
# 画眼睛
pen.penup()
pen.goto(-50, 100)
pen.pendown()
pen.setheading(0)
pen.begin_fill()
pen.color("white")
pen.circle(10)
pen.end_fill()
pen.penup()
pen.goto(-20, 100)
pen.pendown()
pen.setheading(0)
pen.begin_fill()
pen.color("white")
pen.circle(10)
pen.end_fill()
# 画鼻子
pen.penup()
pen.goto(-30, 70)
pen.pendown()
pen.setheading(60)
pen.begin_fill()
pen.color("pink")
pen.circle(10, 120)
pen.setheading(-60)
pen.circle(10, 120)
pen.setheading(180)
pen.circle(10, 120)
pen.end_fill()
# 画嘴巴
pen.penup()
pen.goto(-40, 40)
pen.pendown()
pen.setheading(-60)
pen.color("pink")
pen.circle(40, 120)
# 画耳朵
pen.penup()
pen.goto(-100, 150)
pen.pendown()
pen.setheading(-30)
pen.begin_fill()
pen.color("pink")
pen.circle(30, 260)
pen.setheading(30)
pen.circle(30, 260)
pen.end_fill()
# 画手
pen.penup()
pen.goto(60, 0)
pen.pendown()
pen.setheading(-30)
pen.begin_fill()
pen.color("pink")
pen.circle(30, 260)
pen.setheading(30)
pen.circle(30, 260)
pen.end_fill()
# 画腿
pen.penup()
pen.goto(-60, -150)
pen.pendown()
pen.setheading(-30)
pen.begin_fill()
pen.color("pink")
pen.circle(30, 260)
pen.setheading(30)
pen.circle(30, 260)
pen.end_fill()
pen.penup()
pen.goto(40, -150)
pen.pendown()
pen.setheading(-30)
pen.begin_fill()
pen.color("pink")
pen.circle(30, 260)
pen.setheading(30)
pen.circle(30, 260)
pen.end_fill()
# 完成画图
turtle.done()
```
这段代码使用Python的turtle库来进行画图,首先设置画布和画笔的属性,然后依次使用不同函数绘制小猪佩奇的身体、脸、眼睛、鼻子、嘴巴、耳朵、手和腿的部分,最后通过turtle.done()来显示最终的绘图结果。
阅读全文