turtle画DNA链
时间: 2023-06-20 20:05:38 浏览: 117
python turtle 绘图动画源码
好的,下面是Python代码实现turtle画DNA链的过程:
```python
import turtle
# 设置画笔初始位置
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
# 设置画笔颜色和大小
turtle.color('blue')
turtle.pensize(5)
# 画DNA链
for i in range(50):
if i % 2 == 0:
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
else:
turtle.forward(40)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(40)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
运行以上代码,即可看到turtle绘制的DNA链图案。
阅读全文