python中的乌龟画图

自学了python,看到python中有个turtle模块,乌龟画图,使用这个模块做了随机画五角星的的小程序

python中的乌龟画图

#导入turtle模块
import turtle,random
t = turtle
#设置背景颜色
t.bgcolor('black')
colors = ["red","yellow","green","blue","orange","purple"]
#画星星的方法 x,y表示星的中心点坐标,r为中心点到星角的距离,
#color为填充颜色,heading为设置当前朝向的角度
def drawStar(x, y, r, color):
    t.up()
    #设置颜色
    t.color(color)
    #画笔大小
    #turtle.pensize(5)
    #画笔移动到坐标为x,y的位置
    t.goto(x,y)
    t.down()
    for i in range(6):
        t.forward(r)
        t.right(144)

count =0 
x = -300                   
while count<50:
    #随机画星星、大小随机、
    x = x+10
    y = random.randint(-100,200)
    r = random.randint(10,35) 
    n = random.randint(0,5) #颜色随机  
    drawStar(x, y, r, colors[n])
    count = count+1
    
#签名
t.up()
t.goto(300,-120)
t.color("red")
t.pensize(100)
t.down()
t.write("@Lindy")    
#隐藏画笔
t.hideturtle()
#让画面一直停留
turtle.done()