五颜六色的星星
程序员文章站
2022-03-22 14:22:15
import turtle as tt.bgcolor("dimgray")#定义一个画星星的函数def star(x,y,z,color): """ x,y:位置 z:大小 color:颜色 """ t.penup() t.goto(x,y) t.pendown() t.color(color) t.begin_fill() for i in range(5): t.fd(z)...
import turtle as t
t.bgcolor("dimgray")
#定义一个画星星的函数
def star(x,y,z,color):
"""
x,y:位置
z:大小
color:颜色
"""
t.penup()
t.goto(x,y)
t.pendown()
t.color(color)
t.begin_fill()
for i in range(5):
t.fd(z)
t.left(144)
t.end_fill()
#调用函数
import random as r
t.speed(0)#加速画图
color=("red","yellow","green","orange","pink","blue"\
,"purple","olivedrab","tomato")
for i in range(365):
x=r.randint(-450,450)
y=r.randint(-450,450)
z=r.randint(10,50)
star(x,y,z,color[i%9])
本文地址:https://blog.csdn.net/qq_52077391/article/details/109875778