1 2 3 4

python海龟画图生成星星

import turtle  as tt
import random
from random import randint
tt.setup(1280,720)
tt.bgcolor("black")
tt.colormode(255)
tt.speed(0)
q = 1
while q <= 1000:
B = randint(0, 255)
x = randint(-640, 640)
y = randint(-360, 360)
A = randint(0, 255)
B = randint(0, 255)
C = randint(0, 255)
tt.pencolor(A, B, C)
tt.pu()
tt.goto(x,y)
tt.pd()
a = ['red','yellow','blue','green','pink','purple','pink','white','cyan','gray','coral']
tt.fillcolor(random.choice(a))
tt.begin_fill()
for i in range(6):
tt.forward(15)
tt.left(144)
tt.hideturtle()
q = q + 1
tt.end_fill()
tt.done()


运行效果图:


posted @ 2021-07-08 17:15  320618496  阅读(955)  评论(0编辑  收藏  举报