在jupyter notebook用python画雪花
时间: 2023-10-02 18:04:10 浏览: 38
图解Python编程神器Jupyter Notebook
以下是用 Turtle 绘制雪花的 Python 代码:
```python
import turtle
def snowflake(length_side, levels):
if levels == 0:
turtle.forward(length_side)
return
length_side /= 3.0
snowflake(length_side, levels-1)
turtle.left(60)
snowflake(length_side, levels-1)
turtle.right(120)
snowflake(length_side, levels-1)
turtle.left(60)
snowflake(length_side, levels-1)
turtle.speed("fastest")
for i in range(3):
snowflake(300, 4)
turtle.right(120)
turtle.done()
```
运行代码,你将会得到下面这幅美丽的雪花图案:
![snowflake](https://img-blog.csdn.net/20171221134539616?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQW5nbGlzaF9BbmRyb2lk/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/75)
阅读全文