fireworks.py

Created by schraf

Created on July 14, 2022

1.43 KB


from kandinsky import *
from time import sleep
from random import randint, random, choice

img1 = "!!   o&!  \\\'/! = o =!  /.\\&   :!\'.\\\'/.\'!-= o =-!.\'/.\\\'.!   :&!!-=   =-&!\'. \' !-     !.\' . "
img2 = "! _\\/_!  /\\& .\'\'.!:_\\/_:!: /\\ :! \'..\'& .\'\'.!:    :!:    :! \'..\'!"
img3 = "! _\\/_!  /\\& *  *!*_\\/_*!* /\\ *! *  *& *  *!*    *!*    *! *  *"
img4 = "!!   *&   \'! -\\)/_!  /(\\!   \'"

def efface(): fill_rect(0,0,320,222,(0,0,0))

efface()

class feu:
    def __init__(self,img):
        self.img = img.split("&")
        self.x = randint(0,320)
        self.y = randint(0,150)
        self.pos = 0 
        self.coul = (randint(100,255),randint(100,255),randint(100,255))
    def maj(self):
        if self.pos < len(self.img): 
            if random() < .5:
                txt = self.img[self.pos].split('!')  
                txt.append(" " * 7)
                for k,v in enumerate(txt):
                    draw_string(v,self.x,self.y+k*14,self.coul,(0,0,0))
                self.pos += 1
                self.y -= randint(1,6) 
            return False
        else: 
            for k in range(5): draw_string(" " * 7,self.x,self.y+k*14,self.coul,(0,0,0))
            return True  

feux = []
for k in range(6):
 feux.append(feu(choice([img1,img2,img3,img4])))

while True:
    for f in feux:
        if f.maj():
            feux.remove(f)
            feux.append(feu(choice([img1,img2,img3,img4]))) 
    sleep(.1)