perseides.py

Created by schraf

Created on August 12, 2021

852 Bytes


from turtle import *
from kandinsky import set_pixel,fill_rect
from random import randint
from time import sleep

hideturtle()
speed(0)
fill_rect(0,0,320,222,(0,0,0))

# meteore partant de (x,y)
# de taille t, de direction d
# deplacement de longueur l
# et de couleur (c,c,c)

def perseide(x,y,t,d,l,c):
    penup()
    goto(x,y)
    pensize(t)
    setheading(d)
    color((c,) * 3)
    pendown()
    forward(l)
    penup()

# Les etoiles
for i in range(100):
    x,y,c = randint(0,320), randint(0,220), randint(100,255)
    set_pixel(x,y,(c,)*3)

while True:
    x,y = randint(-150,150), randint(-40,100)
    t,d = randint(1,2), randint(-180,0)
    c,l = randint(1,80), randint(20,100)
    # on affiche
    perseide(x,y,t,d,l,c)
    # on efface
    perseide(x,y,3,d,l,0)
    # temps alea entre 2 meteores
    sleep(randint(1,10)/10)