用Python的turtle库画蛋仔的代码
时间: 2024-04-27 18:05:58 浏览: 295
下面是用Python的turtle库画蛋仔的代码:
```python
import turtle
turtle.speed(0) # 设置画笔移动速度为最快
turtle.penup()
turtle.goto(0, -200) # 将画笔移动到起始位置
turtle.pendown()
turtle.fillcolor("#F5A357") # 设置填充颜色为橙色
turtle.begin_fill() # 开始填充
turtle.circle(200, 270) # 画出半个蛋形
turtle.goto(0, -200) # 回到起始位置
turtle.end_fill() # 结束填充
turtle.fillcolor("#F5A357")
turtle.begin_fill()
turtle.circle(-200, 270) # 画出另一边的半个蛋形
turtle.goto(0, -200)
turtle.end_fill()
# 画出蛋黄
turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.fillcolor("#FFFF00") # 设置填充颜色为黄色
turtle.begin_fill()
turtle.circle(50) # 画出圆形蛋黄
turtle.end_fill()
turtle.done() # 结束绘制,保持窗口不关闭
```
这段代码会绘制出一个橙色的蛋壳和一个黄色的蛋黄,形成一个蛋仔的图案。你可以根据需要修改颜色、大小等参数。
相关问题
python turtle库画史迪奇源代码
```python
import turtle
# 设置画布和海龟
wn = turtle.Screen()
wn.bgcolor("white")
snoopy = turtle.Turtle()
snoopy.shape("turtle")
snoopy.color("black")
# 画脸
snoopy.begin_fill()
snoopy.circle(100)
snoopy.end_fill()
# 画眼睛
snoopy.penup()
snoopy.goto(-35, 120)
snoopy.pendown()
snoopy.dot(25)
snoopy.penup()
snoopy.goto(35, 120)
snoopy.pendown()
snoopy.dot(25)
# 画鼻子
snoopy.penup()
snoopy.goto(0, 90)
snoopy.pendown()
snoopy.dot(15)
# 画嘴巴
snoopy.penup()
snoopy.goto(0, 60)
snoopy.pendown()
snoopy.right(90)
snoopy.circle(20, 180)
# 画耳朵
snoopy.penup()
snoopy.goto(-100, 90)
snoopy.pendown()
snoopy.begin_fill()
snoopy.circle(30, 180)
snoopy.end_fill()
snoopy.penup()
snoopy.goto(100, 90)
snoopy.pendown()
snoopy.begin_fill()
snoopy.circle(30, -180)
snoopy.end_fill()
# 画身体
snoopy.penup()
snoopy.goto(0, -100)
snoopy.pendown()
snoopy.begin_fill()
snoopy.circle(100, -180)
snoopy.left(90)
snoopy.forward(200)
snoopy.left(90)
snoopy.circle(100, -180)
snoopy.end_fill()
# 完成
snoopy.hideturtle()
wn.mainloop()
```
用python turtle库画爱心
以下是使用 Python turtle 库绘制爱心的代码:
```python
import turtle
# 创建画布
canvas = turtle.Screen()
canvas.bgcolor("white")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
pen.color("red", "pink")
pen.penup()
pen.goto(0, -150)
pen.pendown()
# 绘制爱心
pen.begin_fill()
pen.left(45)
pen.forward(200)
pen.circle(100, 180)
pen.left(90)
pen.circle(100, 180)
pen.forward(200)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
运行代码后,将会在画布上绘制一个红色的爱心。
阅读全文