用python的turtle库画一个精美图案
时间: 2024-04-20 11:06:49 浏览: 10
好的,下面是一个简单的例子,画出了一朵花的图案:
```python
import turtle
# 设置画布背景色
turtle.bgcolor('black')
# 设置画笔颜色和形状
turtle.color('white', 'red')
turtle.shape('turtle')
# 循环画花瓣
for _ in range(36):
turtle.left(10)
turtle.begin_fill()
for _ in range(4):
turtle.forward(100)
turtle.left(90)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行后,你可以看到一个美丽的红色花朵在画布上绽放。当然,你也可以根据自己的创意来画出更复杂、更精美的图案。
相关问题
用python turtle库画一个黄色正立的月牙
以下是Python Turtle库画一个黄色正立的月牙的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔颜色和填充颜色
pen.color("yellow")
pen.fillcolor("yellow")
# 开始绘制月牙
pen.begin_fill()
pen.circle(100, 180)
pen.circle(50, 180)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 等待用户关闭画布
canvas.mainloop()
```
运行以上代码,即可在画布上看到一个黄色正立的月牙。
Python turtle库画一个卡通奥特曼
好的,我可以为您提供一段Python代码来使用turtle库画一个卡通奥特曼:
```python
import turtle
# 画奥特曼的脸
turtle.color("red", "yellow")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画奥特曼的眼睛
turtle.penup()
turtle.goto(-40, 120)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 130)
turtle.pendown()
turtle.color("black")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 画奥特曼的身体
turtle.penup()
turtle.goto(-150, -100)
turtle.pendown()
turtle.color("red", "yellow")
turtle.begin_fill()
for i in range(2):
turtle.forward(300)
turtle.circle(-50, 180)
turtle.end_fill()
# 画奥特曼的手
turtle.penup()
turtle.goto(-150, -80)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.forward(50)
turtle.circle(-20, 180)
turtle.forward(50)
turtle.circle(-20, 180)
turtle.end_fill()
turtle.penup()
turtle.goto(150, -80)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.forward(50)
turtle.circle(20, 180)
turtle.forward(50)
turtle.circle(20, 180)
turtle.end_fill()
# 画奥特曼的脚
turtle.penup()
turtle.goto(-100, -250)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.forward(70)
turtle.circle(-35, 180)
turtle.forward(70)
turtle.circle(-35, 180)
turtle.end_fill()
turtle.penup()
turtle.goto(30, -250)
turtle.pendown()
turtle.color("white")
turtle.begin_fill()
turtle.forward(70)
turtle.circle(35, 180)
turtle.forward(70)
turtle.circle(35, 180)
turtle.end_fill()
# 停止画笔并等待用户关闭窗口
turtle.done()
```
运行上述代码,就可以在Python turtle图形界面上看到一个卡通奥特曼的图像了。希望能对您有所帮助!