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)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.