如何用python中的turtle画星空
要用Python中的turtle模块画星空,可以依照以下步骤进行:
import turtle
turtle.setup(width=800, height=600)
turtle.bgcolor('black')
turtle.color('white')
turtle.speed(0)
def draw_star():
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.right(72)
for _ in range(36):
draw_star()
turtle.done()
完全示例代码以下所示:
import turtle
def draw_star():
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.right(72)
turtle.setup(width=800, height=600)
turtle.bgcolor('black')
turtle.color('white')
turtle.speed(0)
for _ in range(36):
draw_star()
turtle.done()
运行以上代码,便可在turtle绘图窗口中看到画出的星空效果。
TOP