Bonjour, ceci est a rendre pour aujourdh'ui, c'est un simulateur de feux d'artifice,
lorsque je lance le programme, rien ne s'affiche.

import tkinter as tk
from random import randint, uniform, choice
from math import radians, cos, sin, exp
from time import sleep

GRAVITY = 2

couleurs = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'gold', 'indigo']

class Fusee:

def __init__(self, cv, idx, total, vitesse_dexplosion, couleur, taille, longevitee, x=0, y=0, vx=0, vy=0):
self.id = idx
self.x = x
self.y = y
self.vitesse_initial = vitesse_dexplosion
self.vx = vx
self.vy = vy
self.total = randint(8,14) #nbr particules
self.age = 0
self.couleur = couleur
self.taille = taille
self.cv = cv
self.longevitee = longevitee
self.cid = None

def create(self):
self.cid = self.cv.create_oval(
self.x, self.y,
self.x + self.taille, self.y + self.taille,
outline=self.couleur, fill=self.couleur)

def vivant(self):
return self.age <= self.longevitee

def explosion(self):
total_particles = self.total
explosion_speed = self.vitesse_initial
particles = []
particule_couleur= choice(couleurs)
for i in range(total_particles):
angle = radians(i * (360 / total_particles))
distance = 360 / total_particles # Ajustement pour la distance entre les particules
position_x = cos(angle) * distance
position_y = sin(angle) * distance

# Création d'une particule (fusee) avec les mêmes propriétés
particle = Fusee(cv=self.cv, idx=0, total=total_particles, longevitee=30,
x=self.x, y=self.y,
vitesse_dexplosion=explosion_speed, taille=self.taille,
couleur=particule_couleur)

particle.create()
particles.append((particle, position_x, position_y))

# Trajectoire ascendante
while any(particle.y > 0 for particle, _, _ in particles):
for particle, move_x, move_y in particles:
particle.x += particle.vx
particle.y -= particle.vy
particle.cv.move(particle.cid, move_x / 20, -move_y / 20)
particle.vy += GRAVITY / 5
particle.cv.update()
sleep(0.001)

# Trajectoire descendante
while any(particle.y < haut_fen for particle, _, _ in particles):
for particle, _, _ in particles:
particle.x += particle.vx
particle.y += particle.vy
particle.vy += GRAVITY / 5 # Ajouter la gravité à la vitesse verticale
particle.cv.move(particle.cid, 0, particle.vy)
particle.cv.update()
sleep(0.1)

# Supprimer les particules après l'explosion
for particle, _, _ in particles:
particle.cv.delete(particle.cid)

def etendre(self):
return self.age <= 2

def maj(self, dt):
self.age += dt
if self.etendre():
self.explosion()

def apparition(self, t=0):
self.x += 7
self.y -= exp(0.06*t)
if self.y > 0:
self.cv.move(self.cid, 7, -exp(0.06*t))
self.cv.update()
self.cv.after(100, self.apparition, t + 1)
if self.y <= hauteur_max:
self.cv.delete(self.cid)
self.maj(2)
return self.x, self.y

def lancer(self):
"""lance un feux d'artifice"""
self.create()
self.apparition()




def simulation(t=0, count=5):
"""plusieur feux artifices a la suite"""
if count > 0:
fusee0 = Fusee(cv, idx=0, total=10, vitesse_dexplosion=10, couleur="white", taille=10, longevitee=10, x=randint(10, large_fen - 650), y=0.9 * haut_fen)
fusee0.lancer()
root.after(100, lambda f=fusee0: f.explosion([])) #explose fusee simultanement
root.after(100, lambda c=count-1: simulation(t, c))#lance fusee simultanement



def pl_sim():
"""effectue plusieurs simulation"""
for l in range(randint(1,5)):
simulation()

root = tk.Tk()
large_fen = root.winfo_screenwidth()
haut_fen = root.winfo_screenheight()
hauteur_max = haut_fen - 0.8 * haut_fen

cv = tk.Canvas(root, bg='black', height=haut_fen, width=large_fen)
cv.pack()

PI_x = randint(10, (large_fen - 650)) #467, distance x parcourue + marge explosion
fusee0 = Fusee(cv, idx=0, total=10, vitesse_dexplosion=10, couleur="white", taille=10, longevitee=10, x=PI_x, y=0.9 * haut_fen)
simulation()
root.mainloop()
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Helpful Social

Copyright © 2024 ELIBRARY.TIPS - All rights reserved.