p ython画蝴蝶结
时间: 2023-07-11 13:16:35 浏览: 232
i p t v.txt
以下是用Python Turtle库绘制蝴蝶结的代码:
```python
import turtle
# 绘制左边的半个蝴蝶结
turtle.color('red', 'pink')
turtle.pensize(2)
turtle.speed(10)
turtle.begin_fill()
while True:
turtle.forward(120)
turtle.left(170)
if abs(turtle.pos()) < 1:
break
turtle.end_fill()
# 绘制右边的半个蝴蝶结
turtle.penup()
turtle.setposition(0, 0)
turtle.pendown()
turtle.begin_fill()
while True:
turtle.forward(120)
turtle.right(170)
if abs(turtle.pos()) < 1:
break
turtle.end_fill()
turtle.done()
```
运行代码后,屏幕上将出现一个粉红色的蝴蝶结。
阅读全文