要用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绘图窗口中看到画出的星空效果。